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. Example: ```ts expressApp.get('/myApi', authorize((req, res) => { console.log('User is authorized', req.adminUser); res.json({ message: 'Hello World' }); })); `` |
Returns
void
endpoint()
endpoint(
options
):void
Method which should register endpoint in HTTP server.
Parameters
Parameter | Type | Description |
---|---|---|
options | object | : 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
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