a
This commit is contained in:
@ -1,19 +1,24 @@
|
||||
|
||||
const express = require("express");
|
||||
const helmet = require("helmet");
|
||||
|
||||
const path = require("path");
|
||||
const app = express();
|
||||
app.use(helmet());
|
||||
const port = 80;
|
||||
|
||||
const bodyParser = require('body-parser'); // Middleware
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
|
||||
app.use(helmet());
|
||||
//disable x-powered-by header for security reasons
|
||||
app.disable("x-powered-by");
|
||||
|
||||
app.use(express.json());
|
||||
app.set("json spaces", 2);
|
||||
|
||||
//public folder with path to static files
|
||||
app.use(express.static(path.join(__dirname, "../public")));
|
||||
|
||||
//middleware logic ( called by next() )
|
||||
//app.use('/api/v0', APIlogger, require('../routes/api_route.js'));
|
||||
//add token middeware upon login to validate routes that require token
|
||||
|
||||
//route logic
|
||||
app.use("/api/v0", require("../routes/api_routes")); //consumerWebsite\routes\api_routes.js
|
||||
@ -28,33 +33,33 @@ app.use(function (req, res, next) {
|
||||
});
|
||||
|
||||
// Error handler. This is where `next()` will go on error
|
||||
app.use(function(err, req, res, next) {
|
||||
app.use(function (err, req, res, next) {
|
||||
console.error(err.status || res.status, err.name, req.method, req.url);
|
||||
if(![ 404].includes(err.status || res.status)){
|
||||
console.error(err.message);
|
||||
console.error(err.stack);
|
||||
console.error('=========================================');
|
||||
if (![404].includes(err.status || res.status)) {
|
||||
console.error(err.message);
|
||||
console.error(err.stack);
|
||||
console.error("=========================================");
|
||||
}
|
||||
|
||||
|
||||
console.log(err.name + " validation error");
|
||||
// Parse key error for Sequilzw
|
||||
let keyErrors = {}
|
||||
if(['SequelizeValidationError'].includes(err.name) && err.errors){
|
||||
for(let item of err.errors){
|
||||
if(item.path){
|
||||
keyErrors[item.path] = item.message
|
||||
let keyErrors = {};
|
||||
if (["SequelizeValidationError"].includes(err.name) && err.errors) {
|
||||
for (let item of err.errors) {
|
||||
if (item.path) {
|
||||
keyErrors[item.path] = item.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
res.status(err.status || 500);
|
||||
console.log(keyErrors);
|
||||
res.json({
|
||||
name: err.name,
|
||||
message: err.message,
|
||||
keyErrors,
|
||||
name: err.name,
|
||||
message: err.message,
|
||||
keyErrors,
|
||||
});
|
||||
});
|
||||
});
|
||||
app.listen(port, () => {
|
||||
console.log(`app listening on port ${port}`);
|
||||
});
|
||||
|
Reference in New Issue
Block a user