Implémentation SkydiverId API
This commit is contained in:
@@ -6,7 +6,8 @@ require('dotenv').config({ path: `.env.${appEnv}` });
|
||||
const { promisify } = require('util'),
|
||||
bodyParser = require('body-parser'),
|
||||
chalk = require('chalk'),
|
||||
utils = require('./routes/utils');
|
||||
utils = require('./routes/utils'),
|
||||
exceptionHandler = require('./middlewares/exceptions.handler.js');
|
||||
var express = require('express'),
|
||||
session = require('express-session'),
|
||||
cors = require('cors'),
|
||||
@@ -23,8 +24,8 @@ app.use(cors());
|
||||
|
||||
// Normal express config defaults
|
||||
//app.use(morgan('combined'));
|
||||
morgan.token('statusColor', (req, res, args) => {
|
||||
var status = (typeof res.headersSent !== 'boolean' ? Boolean(res.header) : res.headersSent)
|
||||
morgan.token('statusColor', (req, res) => {
|
||||
let status = (typeof res.headersSent !== 'boolean' ? Boolean(res.header) : res.headersSent)
|
||||
? res.statusCode
|
||||
: undefined
|
||||
|
||||
@@ -60,55 +61,49 @@ if(isProduction){
|
||||
mongoose.set('debug', process.env.DEBUG);
|
||||
console.log(`${utils.getDateTimeISOString()}`, chalk.red('debug :'), chalk.yellow(process.env.DEBUG));
|
||||
}
|
||||
require('./models/mongo/User');
|
||||
require('./models/mongo/Application');
|
||||
require('./models/mongo/Aeronef');
|
||||
require('./models/mongo/Canopy');
|
||||
require('./models/mongo/Dropzone');
|
||||
require('./models/mongo/Jump');
|
||||
require('./models/mongo/QCM');
|
||||
/*
|
||||
require('./models/mongo/Metal');
|
||||
require('./models/mongo/Price');
|
||||
require('./models/mongo/Product');
|
||||
*/
|
||||
|
||||
require('./models/mongo');
|
||||
require('./config/passport');
|
||||
|
||||
app.use(require('./routes'));
|
||||
|
||||
/// catch 404 and forward to error handler
|
||||
app.use(exceptionHandler.notFoundErrorHandler);
|
||||
app.use(exceptionHandler.logErrorHandler);
|
||||
app.use(exceptionHandler.clientErrorHandler);
|
||||
app.use(exceptionHandler.fianlErrorHandler);
|
||||
|
||||
/*
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function(req, res, next) {
|
||||
var err = new Error('Not Found');
|
||||
let err = new Error('Not Found');
|
||||
err.status = 404;
|
||||
next(err);
|
||||
});
|
||||
|
||||
/// error handlers
|
||||
|
||||
// development error handler
|
||||
// will print stacktrace
|
||||
if (!isProduction) {
|
||||
app.use(function(err, req, res, next) {
|
||||
console.log(`${utils.getDateTimeISOString()}`, chalk.red(`error handler : ${err.message} ${err.err}`));
|
||||
res.status(err.status || 500);
|
||||
// error handler
|
||||
app.use(function(err, req, res, next) {
|
||||
console.log(`${utils.getDateTimeISOString()}`, chalk.red(`error handler : ${err.message} ${err.err}`));
|
||||
if (res.headersSent) {
|
||||
return next(err)
|
||||
}
|
||||
res.status(err.status || 500);
|
||||
if (!isProduction) {
|
||||
// development error handler will print stacktrace
|
||||
res.json({errors: {
|
||||
message: err.message,
|
||||
error: err.err,
|
||||
stack: err.stack
|
||||
}});
|
||||
});
|
||||
} else {
|
||||
// production error handler
|
||||
// no stacktraces leaked to user
|
||||
app.use(function(err, req, res, next) {
|
||||
res.status(err.status || 500);
|
||||
} else {
|
||||
// production error handler no stacktraces leaked to user
|
||||
res.json({errors: {
|
||||
message: err.message,
|
||||
error: {},
|
||||
stack: {}
|
||||
}});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
const startServer = async () => {
|
||||
const port = process.env.SERVER_PORT || 3200;
|
||||
|
||||
Reference in New Issue
Block a user