Skip to main content

ExpressHttpServer

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

ParameterTypeDescription
callableFunction

: 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

ParameterTypeDescription
optionsobject: Object with method, path and handler properties.
options.handler(body, adminUser, query, headers, cookies, response) => void-
options.methodstring-
options.noAuth?boolean-
options.pathstring-

Returns

void

Inherited from

GenericHttpServer . endpoint


serve()

serve(app): void

Call this method to serve AdminForth SPA from Express instance.

Parameters

ParameterTypeDescription
appExpress: 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

Inherited from

GenericHttpServer . setupSpaServer