-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
39 lines (31 loc) · 942 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require('dotenv').config();
import express, { NextFunction, Request, Response } from 'express';
export const app = express();
import cors from "cors";
import cookieParser from 'cookie-parser';
import {ErrorMiddleware} from './middleware/error';
import userRouter from './routes/user.route';
//body parser
app.use(express.json({ limit: "50mb" }));
//cookie parser
app.use(cookieParser());
// cors => cross origin resource sharing
app.use(cors({
origin: process.env.ORIGIN
}));
// routes
app.use('/api/v1', userRouter);
// testing api
app.get("/test", (req: Request, res: Response, next: NextFunction) => {
res.status(200).json({
success: true,
message: "API is working",
});
});
// unknown routes
app.all("*", (req: Request, res: Response, next: NextFunction) => {
const err = new Error(`Route ${req.originalUrl} not found`) as any;
err.statusCode = 404;
next(err);
});
app.use(ErrorMiddleware);