-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (45 loc) · 1.79 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Local App Modules
import './config/config';
import aboutRoute from './routes/about-route';
import homeRoute from './routes/home-route';
import logger from './util/logger-util';
// Library Modules
const express = require('express');
const path = require('path');
const helmet = require('helmet');
const cors = require('cors');
const hpp = require('hpp');
const es6Renderer = require('express-es6-template-engine');
// Set up
const app = express();
const port = process.env.PORT;
const publicPath = path.join(__dirname, './public/dist/');
const logsPath = path.join(__dirname, './log/');
// View: Template engine
app.engine('html', es6Renderer);
app.set('views', 'views');
app.set('view engine', 'html');
// Middlewares ======================> Security
app.use(cors({ origin: false })); // Cross-Origin Resource Sharing is disabled
app.use(helmet()); // Helmet, for security of HTTP requests
// some Security middlewares require to be parsed first
app.use(express.json({ limit: '300kb' })); // Parser for JSON, with limit to avoid payload
app.use(express.urlencoded()); // Parser for x-www-form-urlencoded
// Middlewares ======================> Security continuation...
app.use(hpp()); // protection against Parameter Pollution attacks
// Middlewares ======================> Other
app.use(express.static(publicPath)); // Static Assets
app.use(logger(`${logsPath}/app-logs.json`)); // Logs, using Winston & Express-Winston
// Main routes using express.Router()
app.use('/', homeRoute);
app.use('/about', aboutRoute);
// Ready
app.listen(port, () => {
console.log(`App is listening on port ${port}`);
// Browser-Refresh
// Comment this out before building for Production
// This is only for development, to auto refresh the browser
// if (process.send) {
// process.send('online');
// }
});