-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (38 loc) · 1.08 KB
/
server.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
import express from 'express';
import * as dotenv from 'dotenv';
import routes from './src/routes/index.js';
dotenv.config();
import connect from './src/database/database.js';
import { OutputType, print } from './src/helpers/print.js';
import Exception from './src/exceptions/Exception.js';
import helmet from 'helmet';
import cors from 'cors';
import checkToken from './src/authentication/auth.js';
/**
* App Variables
*/
if (!process.env.PORT) {
print(Exception.APP_VARIABLES_REQUIRED, OutputType.ERROR);
process.exit(1);
}
const app = express();
const port = process.env.PORT ?? 3000;
/**
* App configuration
*/
app.use(checkToken);
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(helmet());
app.use(cors());
app.use('/users', routes.users);
app.use('/unitPrices', routes.unitPrices);
app.use('/parkings', routes.parkings);
app.use('/tickets', routes.tickets);
app.get('/', (req, res) => {
res.send('response from root router');
});
app.listen(port, async () => {
await connect();
print(`Listening on port: ${port}`, OutputType.INFORMATION);
});