mirror of
https://github.com/Foltik/Shimapan
synced 2024-11-30 22:41:47 -05:00
ES6-ify server.js and add SIGINT graceful close
This commit is contained in:
parent
53f58574f0
commit
55ee7161a0
41
server.js
41
server.js
@ -1,28 +1,28 @@
|
|||||||
var express = require('express');
|
const express = require('express');
|
||||||
var bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
var methodOverride = require('method-override');
|
const methodOverride = require('method-override');
|
||||||
var mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
var morgan = require('morgan');
|
const morgan = require('morgan');
|
||||||
var passport = require('passport');
|
const passport = require('passport');
|
||||||
var session = require('express-session');
|
const session = require('express-session');
|
||||||
var sanitizer = require('express-sanitizer');
|
const sanitizer = require('express-sanitizer');
|
||||||
var helmet = require('helmet');
|
const helmet = require('helmet');
|
||||||
|
|
||||||
var app = express();
|
const app = express();
|
||||||
|
|
||||||
var config = require('config');
|
const config = require('config');
|
||||||
if(config.util.getEnv('NODE_ENV') !== 'test') {
|
if(config.util.getEnv('NODE_ENV') !== 'test') {
|
||||||
app.use(morgan('combined'));
|
app.use(morgan('combined'));
|
||||||
}
|
}
|
||||||
|
|
||||||
mongoose.Promise = global.Promise;
|
mongoose.Promise = global.Promise;
|
||||||
mongoose.connect(config.dbHost, {useMongoClient: true});
|
mongoose.connect(config.dbHost, {useMongoClient: true});
|
||||||
var db = mongoose.connection;
|
const db = mongoose.connection;
|
||||||
db.on('error', function(err) {
|
db.on('error', function(err) {
|
||||||
if (err) console.log('MongoDB Connection Error: ', err);
|
if (err) console.log('MongoDB Connection Error: ', err);
|
||||||
});
|
});
|
||||||
var MongoStore = require('connect-mongo')(session);
|
const MongoStore = require('connect-mongo')(session);
|
||||||
var mongoStore = new MongoStore({
|
const mongoStore = new MongoStore({
|
||||||
url: config.dbHost
|
url: config.dbHost
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ app.use(session({
|
|||||||
app.use(passport.initialize());
|
app.use(passport.initialize());
|
||||||
app.use(passport.session());
|
app.use(passport.session());
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(bodyParser.json({ type: 'application/*+json' }))
|
app.use(bodyParser.json({ type: 'application/*+json' }));
|
||||||
app.use(bodyParser.urlencoded({ extended: true }));
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
app.use(bodyParser.text());
|
app.use(bodyParser.text());
|
||||||
app.use(sanitizer());
|
app.use(sanitizer());
|
||||||
@ -53,6 +53,7 @@ app.use(methodOverride('X-HTTP-Method-Override'));
|
|||||||
|
|
||||||
|
|
||||||
//app.use(favicon(__dirname + '/public/img/favicon.ico'));
|
//app.use(favicon(__dirname + '/public/img/favicon.ico'));
|
||||||
|
console.log(__dirname + '/public');
|
||||||
app.use(express.static(__dirname + '/public'));
|
app.use(express.static(__dirname + '/public'));
|
||||||
|
|
||||||
|
|
||||||
@ -61,10 +62,16 @@ require('./config/passport.js');
|
|||||||
|
|
||||||
|
|
||||||
// Start app
|
// Start app
|
||||||
var port = process.env.PORT || 8080;
|
const port = process.env.PORT || 8080;
|
||||||
var server = app.listen(port);
|
const server = app.listen(port);
|
||||||
console.log('Listening on port ', port, '...');
|
console.log('Listening on port ', port, '...');
|
||||||
|
|
||||||
|
// Handle sigint
|
||||||
|
process.on('SIGINT', () => {
|
||||||
|
console.log('Shutting down...');
|
||||||
|
process.exitCode = 0;
|
||||||
|
});
|
||||||
|
|
||||||
// Expose app
|
// Expose app
|
||||||
exports.db = db;
|
exports.db = db;
|
||||||
exports.server = server;
|
exports.server = server;
|
||||||
|
Loading…
Reference in New Issue
Block a user