Created
August 22, 2016 07:58
-
-
Save gfelot/a06e64f59b4971c555a294c9078530e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Module dependencies | |
const express = require('express'); | |
const cluster = require('express-cluster'); // fork the service on different thread | |
const helmet = require('helmet'); // Secure HTTP header | |
const cors = require('cors') | |
const bodyParser = require('body-parser'); // Help to easily parse the body of req/res | |
const port = process.env.PORT || 3000; | |
const mongoose = require('mongoose'); // Manage MongoDB request | |
cluster(function(worker) { | |
const app = express(); | |
// MongoDB config | |
const config = require('./misc/config'); // Config variable like MongoDB credential | |
mongoose.Promise = global.Promise; | |
mongoose.connect(config.getDBConnectionString()); // Config to cnx to mongodb | |
// mongoose.connect(config.getDBConnectionString(), { config: { autoIndex: false } }); | |
// Middleware | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({extended: true})); | |
app.use(helmet.frameguard()); // Default Value - Help to secure request by putting some setting in the header | |
app.use(cors()); // Handling Cross Origin Ressource Sharing | |
// Logfile | |
const log = require('./misc/log/log'); | |
app.use(log); | |
// Config Landingpage to / | |
app.use('/assets', express.static(__dirname + '/public')); | |
app.set('view engine', 'ejs'); | |
// Entry point | |
const entryPoint = require('./routes/entryPoint'); | |
app.get('/', entryPoint.index); | |
app.get('/api', function (req, res) { | |
res.redirect(301, '/'); | |
}) | |
// API Key handler | |
const auth = require('./misc/auth/auth'); | |
app.use(auth); | |
// List | |
const list = require('./routes/list/listRouter'); // Get List endpoints | |
app.use('/api/list', list); | |
// Map | |
const map = require('./routes/map/mapRouter'); // Get List endpoints | |
app.use('/api/map', map); | |
app.listen(port); | |
}, {count: 2}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment