-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (37 loc) · 1.01 KB
/
app.js
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
/* eslint-disable import/first */
import dotenv from 'dotenv';
dotenv.config();
import './database/index.js';
import express from 'express';
import cors from 'cors';
import helmet from 'helmet';
import { resolve } from 'path';
import Sale from './routes/Sale.js';
import Acquisition from './routes/Acquisition.js';
import Income from './routes/Income.js';
const app = express();
const whiteList = [
'https://test-001-frontend.vercel.app',
];
const corsOptions = {
origin(origin, callback) {
if (whiteList.indexOf(origin) !== -1 || !origin) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
},
};
app.use(cors(corsOptions));
app.use(helmet());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Routes
app.use('/', Sale);
app.use('/', Acquisition);
app.use('/', Income);
const port = process.env.PORT || 3001
app.listen(port, () => {
console.log(`Server is running at 3001`);
console.log(`CTRL + click in http://localhost:3001`);
});