|
1 | | -import helmet from 'helmet'; |
2 | | -import compress from 'compression'; |
3 | 1 | import bodyParser from 'body-parser'; |
4 | | -import cookieParser from 'cookie-parser'; |
| 2 | +import compress from 'compression'; |
5 | 3 | import flash from 'connect-flash'; |
6 | | -import express from 'express'; |
7 | | -import * as http from 'http'; |
8 | | -import Logger from '../../../Contexts/Shared/domain/Logger'; |
9 | | -import { registerRoutes } from './routes'; |
| 4 | +import cookieParser from 'cookie-parser'; |
10 | 5 | import cookieSession from 'cookie-session'; |
| 6 | +import errorHandler from 'errorhandler'; |
| 7 | +import express, { Request, Response } from 'express'; |
| 8 | +import Router from 'express-promise-router'; |
| 9 | +import helmet from 'helmet'; |
| 10 | +import * as http from 'http'; |
| 11 | +import httpStatus from 'http-status'; |
11 | 12 | import nunjucks from 'nunjucks'; |
12 | 13 | import path from 'path'; |
13 | | -import errorHandler from 'errorhandler'; |
| 14 | +import Logger from '../../../Contexts/Shared/domain/Logger'; |
14 | 15 | import container from './dependency-injection'; |
| 16 | +import { registerRoutes } from './routes'; |
15 | 17 |
|
16 | 18 | export class Server { |
17 | 19 | private express: express.Express; |
@@ -47,8 +49,15 @@ export class Server { |
47 | 49 | this.express.use(helmet.hidePoweredBy()); |
48 | 50 | this.express.use(helmet.frameguard({ action: 'deny' })); |
49 | 51 | this.express.use(compress()); |
50 | | - registerRoutes(this.express); |
51 | | - this.express.use(errorHandler()); |
| 52 | + const router = Router(); |
| 53 | + router.use(errorHandler()); |
| 54 | + this.express.use(router); |
| 55 | + registerRoutes(router); |
| 56 | + |
| 57 | + router.use((err: Error, req: Request, res: Response, next: Function) => { |
| 58 | + this.logger.error(err); |
| 59 | + res.status(httpStatus.INTERNAL_SERVER_ERROR).send(err.message); |
| 60 | + }); |
52 | 61 | } |
53 | 62 |
|
54 | 63 | async listen(): Promise<void> { |
|
0 commit comments