@tdb/web
Version:
Common condiguration for serving a web-site and testing web-based UI components.
32 lines (28 loc) • 693 B
text/typescript
import { express, middleware, NextFunction, Request, Response } from '..';
import { fsPath } from '../server/common';
export const router = express.router();
router
// Add middleware
.use(myMiddleware)
.use(
middleware.manifest({
rootDir: fsPath.resolve('./src/example/manifest'),
manifestPath: '/manifest',
resourcePath: '/resource',
}),
);
/**
* Custom express middleware.
*/
let total = 0;
export function myMiddleware(req: Request, res: Response, next: NextFunction) {
if (req.method !== 'GET' || req.url !== '/middleware') {
return next();
}
total += 1;
res.send({
msg: 'Middleware Response',
now: new Date(),
total,
});
}