-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (43 loc) · 1.65 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
46
47
48
49
50
51
52
53
54
55
56
'use strict'
const express = require('express');
const compression = require('compression');
const chalk = require('chalk');
const morgan = require('morgan');
const cors = require('cors');
const bodyParser = require('body-parser');
const helmet = require('helmet');
const env = require('dotenv');
const app = express();
const cool = require('cool-ascii-faces');
// init env var
env.config();
// providing a Connect/Express middleware that can be used to enable CORS with various options.
app.use(cors());
app.use(compression());
// Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
app.use(bodyParser.urlencoded({ extended: true }));
// parse application/json
app.use(bodyParser.json());
// Helmet helps you secure your Express apps by setting various HTTP headers. It’s not a silver bullet, but it can help!
// DOC: https://helmetjs.github.io/
app.use(helmet());
// HTTP request logger middleware
app.use(morgan('dev'));
// setup the winston stream
// app.use(morgan('combined', { "stream": winston.stream.write }));
// default route
app.get("/", (req, res, next) => {
return res.status(200).json({ message: "Welcome to JazzFit Api", cheers: cool() });
});
// import all routes at once
require('./src/utilities/routes.utils')(app);
const publicDir = require('path').join(__dirname, './public/img');
app.use(express.static(publicDir));
// Handling non-existing routes
require('./src/utilities/error-handler.utils')(app);
// db config
require('./src/config/db.config');
const port = process.env.PORT;
app.listen(port, () => {
console.log(`%s Server is listening on port ${port}`, chalk.green('✓'));
});