-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abb85c6
commit e6e6481
Showing
26 changed files
with
2,469 additions
and
594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,8 +50,8 @@ npm start | |
> [email protected] start | ||
> node app.js | ||
info: We are working on DEVELOPMENT environment and Listening on port 3000... | ||
info: MongoDB connection succeeded! | ||
info: We are working on DEVELOPMENT environment and Listening on port 3000... {"timestamp":"2022-10-05 16:57:19:551"} | ||
info: MongoDB connection succeeded! {"timestamp":"2022-10-05 16:57:19:574"} | ||
``` | ||
8) Open the link http://localhost:3000/api-docs in browser and it will open the swagger | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
require('dotenv').config(); | ||
const config = require('config'); | ||
const winston = require('winston'); | ||
const express = require('express'); | ||
const app = express(); | ||
|
||
// LOAD INITIALIZER | ||
require('./util/general.helper').bootstrap('../initializer', [app, config, winston]); | ||
require('./initializer'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
module.exports = [ | ||
require("./global.initializer"), | ||
require("./logging.initializer"), | ||
require("./swagger.initializer"), | ||
require("./language.initializer"), | ||
require("./route.initializer"), | ||
require("./db.initializer"), | ||
|
||
// Put this at last step ... | ||
require("./server.initializer") | ||
]; | ||
const config = require('config'); | ||
const express = require('express'); | ||
const app = express(); | ||
|
||
require("./global.initializer")(app, config); | ||
require("./validation.initializer")(app, config); | ||
require("./logging.initializer")(app, config); | ||
require("./swagger.initializer")(app, config); | ||
require("./language.initializer")(app, config); | ||
require("./route.initializer")(app, config); | ||
require("./db.initializer")(app, config); | ||
|
||
// Put this at last step ... | ||
require("./server.initializer")(app, config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,26 @@ | ||
const fs = require('fs'); | ||
// require('winston-mongodb'); | ||
require('express-async-errors'); | ||
|
||
module.exports = (app, config, winston) => { | ||
|
||
if (!config.get('log.enable')) return false; | ||
|
||
// EXCEPTION | ||
if (config.get('log.exception.enable')) { | ||
const exception = config.get('log.exception'); | ||
!fs.existsSync(exception.dir) && fs.mkdirSync(exception.dir); | ||
winston.handleExceptions( | ||
new winston.transports.Console(exception.console_options), | ||
new winston.transports.File({ filename: `${exception.dir}/${exception.filename}` }) | ||
); | ||
} | ||
const winston = require("winston"); | ||
|
||
module.exports = (app, config) => { | ||
|
||
//@ { error: 0, warn: 1, info: 2, http: 3, verbose: 4, debug: 5, silly: 6 } | ||
const log = config.get('log'); | ||
winston.loggers.add('general', { | ||
format: winston.format.combine( | ||
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss:SSS' }), | ||
winston.format.json() | ||
), | ||
transports: [ | ||
new winston.transports.Console({ level: log.logging.level, format: winston.format.simple() }), | ||
new winston.transports.File({ filename: log.logging.path, level: log.logging.level }), | ||
new winston.transports.File({ filename: log.exception.path, level: log.exception.level }) | ||
], | ||
level: log.level, | ||
silent: !config.get('log.enable'), | ||
exitOnError: false | ||
}); | ||
|
||
// UNHANDLED REJECTION | ||
if (config.get('log.rejection.enable')) | ||
process.on('unhandledRejection', (ex) => { | ||
throw ex; | ||
}); | ||
|
||
// LOGGING | ||
if (config.get('log.logging.enable')) { | ||
const logging = config.get('log.logging'); | ||
!fs.existsSync(logging.dir) && fs.mkdirSync(logging.dir); | ||
winston.add(winston.transports.File, { filename: `${logging.dir}/${logging.filename}` }); | ||
} | ||
|
||
// MONGO LOG CONNECTION | ||
if (config.get('log.db.enable')) { | ||
const db = config.get('log.db'); | ||
winston.add(winston.transports.MongoDB, { | ||
db: config.get('mongodb.uris'), | ||
collection: db.collection, | ||
level: db.level, | ||
options: db.options | ||
}); | ||
} | ||
|
||
// process.on('uncaughtException', function(error) { | ||
// if(!error.isOperational) process.exit(1); | ||
// }); | ||
|
||
// process.on('unhandledRejection', function(reason, p){ | ||
// console.log(reason, p); | ||
// }); | ||
if (config.get('log.rejection.enable')) process.on('unhandledRejection', (ex) => { throw ex; }); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
module.exports = async (app, config, winston) => { | ||
const winston = require('winston').loggers.get('general'); | ||
|
||
module.exports = async (app, config) => { | ||
|
||
const port = process.env.PORT || config.get('server.port'); | ||
await app.listen(port, () => { | ||
winston.info(`We are working on ${config.get('mode').toUpperCase()} environment and Listening on port ${port}...`) | ||
}) | ||
.on("error", (err) => { | ||
winston.log("error", err.message); | ||
winston.error(err.message); | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const Joi = require('joi'); | ||
|
||
module.exports = () => { | ||
Joi.objectId = require('joi-objectid')(Joi); | ||
} |
Oops, something went wrong.