forked from ONDC-Official/log-validation-utility
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.ts
More file actions
38 lines (35 loc) · 1.27 KB
/
app.ts
File metadata and controls
38 lines (35 loc) · 1.27 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
import express, { Application } from 'express'
import healthRoutes from './routes/healthCheck'
import validateRoutes from './routes/validate'
import swaggerUi from 'swagger-ui-express';
import swaggerDocument from './swagger_output.json';
import path from 'path';
import cors from 'cors'
const createServer = (): express.Application => {
const app: Application = express()
const allowedOrigins = process.env.ALLOWED_ORIGINS
app.use(
cors({
origin: function (origin, callback) {
if (!origin) return callback(null, true)
if (allowedOrigins?.indexOf(origin) === -1) {
const msg = 'The CORS policy for this site does not allow access from the specified Origin.'
return callback(new Error(msg), false)
}
return callback(null, true)
},
}),
)
// Body parsing Middleware
app.use(express.json({ limit: '50mb' }))
app.use(express.static(path.join(__dirname, 'frontend')))
// For all other routes, serve index.html (React Router support)
app.get('/', (_, res) => {
res.sendFile(path.join(__dirname, 'frontend', 'index.html'))
})
app.use('/health', healthRoutes)
app.use('/api', validateRoutes)
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
return app
}
export default createServer