-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
37 lines (31 loc) · 1.06 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
// dependencies
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import cacheControl from 'express-cache-controller';
import mariadb from 'mariadb';
import { config } from './api/config';
import routes from './api/routes';
// app initialization with express on port 3004 (3005 for development)
const app = express();
const port = process.env.NODE_ENV === 'development' ? '3005' : '3004';
// creates the pool according to the config
app.locals.pool = mariadb.createPool(config);
// adds middleware to the app
app.use(cors());
app.use(cacheControl({ maxAge: 21600 }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/v1', routes);
// sends error 404 message if necessary
app.use((req, res) => {
res.cacheControl = { noCache: true };
res.status(404).send({ url: `${req.originalUrl} not found` });
});
// connection to port
// app.listen(port, () => {
// console.log(`SikhiFM API start on port ${port}`);
// });
app.listen(port, () => {
console.log(`SikhiFM API start on port ${port}`);
});