-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (64 loc) · 1.58 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
/**
* Loads environment variables from .env file into process.env
*/
require('dotenv').config();
const bodyParser = require('body-parser');
const express = require('express');
const routers = require('./webserver/routes');
const mysqlPool = require('./database/mysql-pool');
const app = express();
app.use(bodyParser.json());
/**
* CORS configuration
*/
app.use((req, res, next) => {
const accessControlAllowMethods = [
'GET',
'POST',
'DELETE',
'HEAD',
'PATCH',
'PUT',
'OPTIONS',
];
const accessControlAllowHeaders = [
'Origin',
'X-Requested-With',
'Content-Type',
'Accept',
'Accept-Version',
'Authorization',
'Location',
];
res.setHeader('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Methods', accessControlAllowMethods.join(','));
res.header('Access-Control-Allow-Headers', accessControlAllowHeaders.join(','));
res.header('Access-Control-Expose-Headers', accessControlAllowHeaders.join(','));
next();
});
/**
* Endpoints
*/
app.use('/api', routers.accountRouter);
app.use('/api', routers.concertRouter);
app.use('/api', routers.concerthallRouter);
app.use('/api', routers.userRouter);
app.use('/api', routers.searchRouter);
/**
* Port variable configured for deploy
*/
const port = process.env.PORT;
async function init() {
try {
await mysqlPool.connect();
} catch (e) {
console.error(e);
process.exit(1);
}
app.listen(port, () => {
console.log(`App listening on ${port}!`);
});
}
init();