update: add morgan for http logging
This commit is contained in:
Generated
+47
@@ -38,6 +38,7 @@
|
||||
"moment-jalaali": "^0.9.2",
|
||||
"mongoose": "^5.12.5",
|
||||
"mongoose-paginate-v2": "^1.3.18",
|
||||
"morgan": "^1.10.0",
|
||||
"nodemailer": "^6.6.0",
|
||||
"nodemon": "^3.1.2",
|
||||
"nuxt": "^2.15.3",
|
||||
@@ -6293,6 +6294,24 @@
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/basic-auth": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
|
||||
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safe-buffer": "5.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/basic-auth/node_modules/safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/bcryptjs": {
|
||||
"version": "2.4.3",
|
||||
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
|
||||
@@ -13299,6 +13318,34 @@
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/morgan": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz",
|
||||
"integrity": "sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"basic-auth": "~2.0.1",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~2.0.0",
|
||||
"on-finished": "~2.3.0",
|
||||
"on-headers": "~1.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/morgan/node_modules/on-finished": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
|
||||
"integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ee-first": "1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/move-concurrently": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
"moment-jalaali": "^0.9.2",
|
||||
"mongoose": "^5.12.5",
|
||||
"mongoose-paginate-v2": "^1.3.18",
|
||||
"morgan": "^1.10.0",
|
||||
"nodemailer": "^6.6.0",
|
||||
"nodemon": "^3.1.2",
|
||||
"nuxt": "^2.15.3",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+50
-39
@@ -1,16 +1,22 @@
|
||||
const express = require('express');
|
||||
const database = require('./database');
|
||||
const fileUpload = require('express-fileupload');
|
||||
const { isUser, isAdmin, isLoggedIn, hasPermission } = require('./authentication');
|
||||
const bodyParser = require('body-parser');
|
||||
const cronJobs = require('./plugins/cronJobs');
|
||||
const express = require("express");
|
||||
const database = require("./database");
|
||||
const fileUpload = require("express-fileupload");
|
||||
const morgan = require("morgan");
|
||||
const {
|
||||
isUser,
|
||||
isAdmin,
|
||||
isLoggedIn,
|
||||
hasPermission,
|
||||
} = require("./authentication");
|
||||
const bodyParser = require("body-parser");
|
||||
const cronJobs = require("./plugins/cronJobs");
|
||||
const swaggerJsdoc = require("swagger-jsdoc");
|
||||
const cors = require('cors')
|
||||
const cors = require("cors");
|
||||
const swaggerUi = require("swagger-ui-express");
|
||||
const { createAdmins } = require('./plugins/privateAdmin');
|
||||
const portals = require('./plugins/portals');
|
||||
global._ = require('lodash');
|
||||
global.lodash = require('lodash-contrib');
|
||||
const { createAdmins } = require("./plugins/privateAdmin");
|
||||
const portals = require("./plugins/portals");
|
||||
global._ = require("lodash");
|
||||
global.lodash = require("lodash-contrib");
|
||||
global.portal = [];
|
||||
|
||||
for (const item of portals) {
|
||||
@@ -20,6 +26,11 @@ for (const item of portals) {
|
||||
// Create express instance
|
||||
const app = express();
|
||||
|
||||
app.set("trust proxy", 1);
|
||||
app.disable("x-powered-by");
|
||||
|
||||
app.use(morgan("combined"));
|
||||
|
||||
const options = {
|
||||
definition: {
|
||||
openapi: "3.0.0",
|
||||
@@ -34,12 +45,12 @@ const options = {
|
||||
components: {
|
||||
securitySchemes: {
|
||||
bearerAuth: {
|
||||
type: 'http',
|
||||
in: 'header',
|
||||
name: 'Authorization',
|
||||
description: 'Bearer Token',
|
||||
scheme: 'bearer',
|
||||
bearerFormat: 'JWT',
|
||||
type: "http",
|
||||
in: "header",
|
||||
name: "Authorization",
|
||||
description: "Bearer Token",
|
||||
scheme: "bearer",
|
||||
bearerFormat: "JWT",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -52,46 +63,46 @@ const options = {
|
||||
},
|
||||
],
|
||||
},
|
||||
apis: ['./server/routes/*.js']
|
||||
apis: ["./server/routes/*.js"],
|
||||
};
|
||||
|
||||
const specs = swaggerJsdoc(options);
|
||||
// const specs = swaggerJsdoc(options);
|
||||
|
||||
cronJobs();
|
||||
createAdmins();
|
||||
const corsOptions = {
|
||||
origin:'*',
|
||||
origin: "*",
|
||||
credentials: true,
|
||||
optionSuccessStatus: 200,
|
||||
}
|
||||
};
|
||||
|
||||
// Init body-parser options (inbuilt with express)
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(fileUpload());
|
||||
app.use(cors(corsOptions))
|
||||
app.use(
|
||||
"/v1",
|
||||
swaggerUi.serve,
|
||||
swaggerUi.setup(specs , {explorer:true})
|
||||
);
|
||||
app.use(cors(corsOptions));
|
||||
// app.use(
|
||||
// "/v1",
|
||||
// swaggerUi.serve,
|
||||
// swaggerUi.setup(specs , {explorer:true})
|
||||
// );
|
||||
// Require & Import API routes
|
||||
const Public = require('./routes/public');
|
||||
const admin = require('./routes/admin');
|
||||
const auth = require('./routes/auth');
|
||||
const user = require('./routes/user');
|
||||
const Public = require("./routes/public");
|
||||
const admin = require("./routes/admin");
|
||||
const auth = require("./routes/auth");
|
||||
const user = require("./routes/user");
|
||||
|
||||
// Use API Routes
|
||||
app.use('/public', Public);
|
||||
app.use('/auth', auth);
|
||||
app.use('/admin', [isLoggedIn, isAdmin], admin);
|
||||
app.use("/public", Public);
|
||||
app.use("/auth", auth);
|
||||
app.use("/admin", [isLoggedIn, isAdmin], admin);
|
||||
// app.use('/user', isUser, user);
|
||||
|
||||
// Error handling middleware to catch buffer issues
|
||||
app.use((err, req, res, next) => {
|
||||
if (err.code === 'ENOBUFS') {
|
||||
console.error('Buffer space error:', err);
|
||||
res.status(500).send('Server is experiencing buffer space issues.');
|
||||
if (err.code === "ENOBUFS") {
|
||||
console.error("Buffer space error:", err);
|
||||
res.status(500).send("Server is experiencing buffer space issues.");
|
||||
} else {
|
||||
next(err);
|
||||
}
|
||||
@@ -99,6 +110,6 @@ app.use((err, req, res, next) => {
|
||||
|
||||
// Export the server middleware
|
||||
module.exports = {
|
||||
path: '/api',
|
||||
handler: app
|
||||
path: "/api",
|
||||
handler: app,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user