mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add not found handler
This commit is contained in:
@@ -5,11 +5,13 @@ import express from 'express';
|
||||
import bodyParser from 'body-parser';
|
||||
import { errorHandler } from './error';
|
||||
import itemsRouter from './routes/items';
|
||||
import notFoundHandler from './routes/not-found';
|
||||
|
||||
const app = express()
|
||||
.disable('x-powered-by')
|
||||
.use(bodyParser.json())
|
||||
.use('/items', itemsRouter)
|
||||
.use(notFoundHandler)
|
||||
.use(errorHandler);
|
||||
|
||||
export default app;
|
||||
|
||||
8
src/routes/not-found.ts
Normal file
8
src/routes/not-found.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { RequestHandler } from 'express';
|
||||
import APIError, { ErrorCode } from '../error';
|
||||
|
||||
const notFound: RequestHandler = (req, res, next) => {
|
||||
throw new APIError(ErrorCode.NOT_FOUND, `Route ${req.path} not found.`);
|
||||
};
|
||||
|
||||
export default notFound;
|
||||
Reference in New Issue
Block a user