Skip to content

Commit

Permalink
Add logging using morgan
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthlogic committed Oct 5, 2023
1 parent 3665867 commit a55af2f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 8 deletions.
5 changes: 4 additions & 1 deletion fly.staging.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ primary_region = "sin"
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]
processes = ["app"]

[env]
LOGGING = true
74 changes: 69 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
"dependencies": {
"express": "^4.18.2",
"google-play-scraper": "^10.0.0",
"npm-check-updates": "^16.14.4",
"morgan": "^1.10.0",
"postman-to-openapi": "^3.0.1",
"swagger-ui-express": "^5.0.0"
},
"devDependencies": {
"eslint": "^8.49.0",
"eslint": "^8.50.0",
"eslint-config-semistandard": "^17.0.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^5.0.0",
"npm-check-updates": "^16.14.5",
"newman": "^5.3.2",
"newman-reporter-htmlextra": "^1.22.11"
}
Expand Down
7 changes: 7 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import Express from 'express';
import router from './lib/index.js';
import swaggerDocument from './openapi/swagger.json' assert { type: "json" };
import swaggerUi from 'swagger-ui-express';
import morgan from 'morgan';

const app = Express();
const port = process.env.PORT || 3000;
const logging = process.env.LOGGING || false;


var options = {
customCss: '.swagger-ui .topbar { display: none }'
Expand All @@ -17,6 +20,10 @@ app.use('/openapi.json', Express.static('openapi/swagger.json'));
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));
app.use('/api/', router);

if (logging === true) {
app.use(morgan(':remote-addr :method :url :response-time'));
}

app.get('/', function (req, res) {
res.redirect('/api-docs');
});
Expand Down

0 comments on commit a55af2f

Please sign in to comment.