IExpressHttpServer
Implement this interface to create custom HTTP server adapter for AdminForth.
Extends
Methods
authorize()
authorize(
callable):void
Method (middleware) to wrap express endpoints with authorization check. Adds adminUser to request object if user is authorized. Drops request with 401 status if user is not authorized.
Parameters
| Parameter | Type | Description |
|---|---|---|
callable | Function | : Function which will be called if user is authorized. |
Returns
void
Example
expressApp.get('/myApi', authorize((req, res) => {
console.log('User is authorized', req.adminUser);
res.json({ message: 'Hello World' });
}));
endpoint()
endpoint(
options):void
Method which should register endpoint in HTTP server.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | { handler: (body, adminUser, query, headers, cookies, response) => void; method: string; noAuth?: boolean; path: string; } | : Object with method, path and handler properties. |
options.handler | (body, adminUser, query, headers, cookies, response) => void | - |
options.method | string | - |
options.noAuth? | boolean | - |
options.path | string | - |
Returns
void
Inherited from
listen()
Call Signature
listen(
port,callback):void
Method to start listening on port.
Parameters
| Parameter | Type |
|---|---|
port | number |
callback | Function |
Returns
void
Call Signature
listen(
port,host,callback):void
Parameters
| Parameter | Type |
|---|---|
port | number |
host | string |
callback | Function |
Returns
void
serve()
serve(
app):void
Call this method to serve AdminForth SPA from Express instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
app | Express | : Express instance |
Returns
void
setupSpaServer()
setupSpaServer():
void
Sets up HTTP server to serve AdminForth SPA.
if hotReload is true, it should proxy all requests and headers to Vite dev server at http://localhost:5173$\{req.url\}
otherwise it should serve AdminForth SPA from dist folder. See Express for example.
Returns
void