Files
bps/src/app.ts
T

21 lines
485 B
TypeScript

import express from 'express';
import { errorHandler } from './middleware/errorHandler';
import { AppError } from './utils/AppError';
const app = express();
// 中间件
app.use(express.json());
// 路由
// ... 你的路由配置 ...
// 处理未找到的路由
app.all('*', (req, res, next) => {
next(new AppError(`Can't find ${req.originalUrl} on this server!`, 404));
});
// 错误处理中间件 (必须放在所有路由之后)
app.use(errorHandler);
export default app;