1
0
forked from fr/deguapp
deguapp/api/src/app.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-04-29 21:26:04 +02:00
import express from "express";
import morgan from "morgan";
2024-05-02 01:15:55 +02:00
import path from 'path'
import cors from 'cors'
2024-05-02 01:15:55 +02:00
import cookieParser from 'cookie-parser'
2024-04-29 21:26:04 +02:00
import { router as routes } from "./routes";
//import { router as middlewares } from './middlewares'
import env from './config/environment'
2024-04-29 21:26:04 +02:00
export let corsWhitelist: Array<string>
if (env.CORS_WHITELIST != 'undefined') {
corsWhitelist = [...['http://localhost:8080', 'http://localhost:6040'], ...env.CORS_WHITELIST.split(';')]
} else {
corsWhitelist = ['http://localhost:8080', 'http://localhost:6040']
}
const corsOptions = {
origin: function (origin: any, callback: any) {
if (!origin || corsWhitelist.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
},
optionsSuccessStatus: 200,
credentials: true
}
2024-04-29 21:26:04 +02:00
export const app = express();
// Middlewares
//app.use(middlewares)
//app.set('view engine', 'ejs')
//app.set('views', path.join(__dirname, 'views'))
app.use(cors(corsOptions))
2024-04-29 21:26:04 +02:00
app.use(morgan("dev"));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
2024-05-02 01:15:55 +02:00
app.use(express.static(path.join(__dirname, 'public')))
app.use(cookieParser())
2024-04-29 21:26:04 +02:00
// Routes
app.use(routes);