-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathserver.js
44 lines (37 loc) · 1.13 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
/* eslint-disable no-console */
import express from 'express';
import db from './database/initializeDB.js';
import apiRoutes from './routes/apiRoutes.js';
import diningRoute from './routes/diningRoute.js';
import mealsRoute from './routes/mealsRoute.js';
import macrosRoute from './routes/macrosRoute.js';
import restrictionsRoute from './routes/restrictionsRoute.js';
const app = express();
const PORT = process.env.PORT || 3000;
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
next();
});
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use('/api', apiRoutes);
app.use('/api/dining', diningRoute);
app.use('/api/meals', mealsRoute);
app.use('/api/macros', macrosRoute);
app.use('/api/restrictions', restrictionsRoute);
async function bootServer() {
try {
const mysql = await db.sequelizeDB;
await mysql.sync();
app.listen(PORT, () => {
console.log(`Listening on: http//localhost:${PORT}`);
});
} catch (err) {
console.error(err);
}
}
bootServer();