-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
47 lines (40 loc) · 1.5 KB
/
app.ts
File metadata and controls
47 lines (40 loc) · 1.5 KB
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
40
41
42
43
44
45
46
47
import "dotenv/config"
import express, { Application, Request, Response, NextFunction } from "express"
import helmet from "helmet"
import cors from "cors"
import testRoutes from "./routes/test"
import HttpException, { sanitize } from "./shared/http-exception"
import locals from "./shared/locals.json"
const createServer = (): express.Application => {
const app: Application = express()
app.use(helmet({ crossOriginResourcePolicy: false }))
app.use(cors({ origin: "*" })) // change this as per requirement
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use("/test", testRoutes)
// eslint-disable-next-line no-unused-vars
app.get("/", async (_req: Request, res: Response): Promise<Response> => {
return res.status(200).send({
success: true,
message: "The server is running",
})
})
// eslint-disable-next-line no-unused-vars
app.get("/health", async (_req: Request, res: Response): Promise<Response> => {
return res.status(200).send({
success: true,
message: "The server is running",
})
})
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
app.use((_req, _res) => {
throw new HttpException(404, locals.notFound)
})
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
app.use((err: any, _req: Request, res: Response, _next: NextFunction) => {
err = sanitize(err)
return res.status(err.status).json({ err: err.message })
})
return app
}
export default createServer