1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-10 15:48:27 -05:00

Add different config for morgan logging

This commit is contained in:
Jack Foltz 2018-07-25 10:18:29 -04:00
parent ce99433afc
commit a00a3efbf6
Signed by: foltik
GPG Key ID: 303F88F996E95541
4 changed files with 17 additions and 19 deletions

View File

@ -1,3 +1,4 @@
{ {
"dbHost": "mongodb://localhost:27017/shimapan" "dbHost": "mongodb://localhost:27017/shimapan",
"httpLogLevel": "combined"
} }

View File

@ -1,3 +1,4 @@
{ {
"dbHost": "mongodb://localhost:27017/shimapan" "dbHost": "mongodb://localhost:27017/shimapan",
"httpLogLevel": "dev"
} }

View File

@ -1,3 +1,4 @@
{ {
"dbHost": "mongodb://localhost:27017/shimapan-test" "dbHost": "mongodb://localhost:27017/shimapan-test",
"httpLogLevel": "dev"
} }

View File

@ -9,24 +9,18 @@ const sanitizer = require('express-sanitizer');
const helmet = require('helmet'); const helmet = require('helmet');
const app = express(); const app = express();
const config = require('config'); const config = require('config');
if(config.util.getEnv('NODE_ENV') !== 'test') {
app.use(morgan('combined'));
}
mongoose.Promise = global.Promise; // MongoDB
mongoose.connect(config.dbHost, {useNewUrlParser: true}); mongoose.connect(config.dbHost, {useNewUrlParser: true});
const db = mongoose.connection; const db = mongoose.connection;
db.on('error', function(err) {
if (err) console.log('MongoDB Connection Error: ', err);
});
const MongoStore = require('connect-mongo')(session); const MongoStore = require('connect-mongo')(session);
const mongoStore = new MongoStore({ const mongoStore = new MongoStore({url: config.dbHost});
url: config.dbHost
});
// HTTP Request Logging
app.use(morgan(config.httpLogLevel));
// Session setup
app.use(helmet()); app.use(helmet());
app.set('trust proxy', 1); app.set('trust proxy', 1);
app.use(session({ app.use(session({
@ -42,6 +36,8 @@ app.use(session({
maxAge: 1000 * 60 * 60 maxAge: 1000 * 60 * 60
} }
})); }));
// Middleware
app.use(passport.initialize()); app.use(passport.initialize());
app.use(passport.session()); app.use(passport.session());
app.use(bodyParser.json()); app.use(bodyParser.json());
@ -51,19 +47,18 @@ app.use(bodyParser.text());
app.use(sanitizer()); app.use(sanitizer());
app.use(methodOverride('X-HTTP-Method-Override')); app.use(methodOverride('X-HTTP-Method-Override'));
// Static directories and favicon
//app.use(favicon(__dirname + '/public/img/favicon.ico')); //app.use(favicon(__dirname + '/public/img/favicon.ico'));
app.use(express.static(__dirname + '/public')); app.use(express.static(__dirname + '/public'));
// Install routes and configure authentication strategy
require('./app/routes/routes.js')(app); require('./app/routes/routes.js')(app);
require('./config/passport.js'); require('./config/passport.js');
// Start app // Start app
const 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 + '...\n');
// Handle sigint // Handle sigint
process.on('SIGINT', () => { process.on('SIGINT', () => {