From 967a35862b765bcd8a30edea01a4f61551b1f8a5 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Tue, 19 Nov 2019 06:11:31 -0800 Subject: [PATCH 1/3] Emit Heroku-like logs from the Fastboot server --- fastboot.js | 11 ++++++++++- package-lock.json | 1 - package.json | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fastboot.js b/fastboot.js index 5c50b9b7888..1960c3cf80c 100644 --- a/fastboot.js +++ b/fastboot.js @@ -10,6 +10,8 @@ const FastBootAppServer = require('fastboot-app-server'); // because fastboot-app-server uses cluster, but it might change in future const cluster = require('cluster'); +const morgan = require('morgan') + class LoggerWithoutTimestamp { constructor() { this.prefix = cluster.isMaster ? 'master' : 'worker'; @@ -44,16 +46,23 @@ function writeAppInitializedWhenReady(logger) { } var logger = new LoggerWithoutTimestamp(); - logger.writeLine(`${os.cpus().length} cores available`); let workerCount = process.env.WEB_CONCURRENCY || 1; +let logRequests = morgan('at=info method=:method path=":url" ' + + 'request_id=:req[x-request-id] ' + + 'fwd=":req[x-real-ip]" ' + + 'user_agent=:req[user-agent]'); let server = new FastBootAppServer({ distPath: 'dist', port: 9000, ui: logger, workerCount: workerCount, + + // afterMiddleware won't be called since Fastboot's middleware + // doesn't call next(). + beforeMiddleware: app => app.use(logRequests), }); if (!cluster.isWorker) { diff --git a/package-lock.json b/package-lock.json index 3811782c8f5..3d17160b62a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16928,7 +16928,6 @@ "version": "1.9.1", "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz", "integrity": "sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA==", - "dev": true, "requires": { "basic-auth": "~2.0.0", "debug": "2.6.9", diff --git a/package.json b/package.json index 698347610a7..57252176b93 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,7 @@ "trailingComma": "all" }, "dependencies": { - "fastboot-app-server": "^2.0.0" + "fastboot-app-server": "^2.0.0", + "morgan": "^1.9.1" } } From 4d70de82ee21d38ef14a3fb2f8d5f91551859452 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Tue, 19 Nov 2019 06:27:14 -0800 Subject: [PATCH 2/3] Fix styling issues "npm run prettier" should include fastboot.js, since "npm lint:js" checks the file. --- .prettierignore | 1 + fastboot.js | 12 +++++++----- package.json | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000000..849ddff3b7e --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +dist/ diff --git a/fastboot.js b/fastboot.js index 1960c3cf80c..b17fe80d5de 100644 --- a/fastboot.js +++ b/fastboot.js @@ -10,7 +10,7 @@ const FastBootAppServer = require('fastboot-app-server'); // because fastboot-app-server uses cluster, but it might change in future const cluster = require('cluster'); -const morgan = require('morgan') +const morgan = require('morgan'); class LoggerWithoutTimestamp { constructor() { @@ -49,10 +49,12 @@ var logger = new LoggerWithoutTimestamp(); logger.writeLine(`${os.cpus().length} cores available`); let workerCount = process.env.WEB_CONCURRENCY || 1; -let logRequests = morgan('at=info method=:method path=":url" ' + - 'request_id=:req[x-request-id] ' + - 'fwd=":req[x-real-ip]" ' + - 'user_agent=:req[user-agent]'); +let logRequests = morgan( + 'at=info method=:method path=":url" ' + + 'request_id=:req[x-request-id] ' + + 'fwd=":req[x-real-ip]" ' + + 'user_agent=:req[user-agent]', +); let server = new FastBootAppServer({ distPath: 'dist', diff --git a/package.json b/package.json index 57252176b93..8da06a5cb5b 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "lint:hbs": "ember-template-lint app/templates", "lint:js": "eslint . --cache", "lint:deps": "ember dependency-lint", - "prettier": "prettier --write '{app,tests,mirage}/**/*.js'", + "prettier": "prettier --write '**/*.js'", "start": "./script/ember.sh serve", "start:live": "./script/ember.sh serve --proxy https://crates.io", "start:local": "./script/ember.sh serve --proxy http://127.0.0.1:8888", From b72684b71867e3cd3e1fffa6d05f251bd03a8c24 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Fri, 22 Nov 2019 16:00:51 -0800 Subject: [PATCH 3/3] Quote user_agent as like the Rust server --- fastboot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastboot.js b/fastboot.js index b17fe80d5de..0bd560c8978 100644 --- a/fastboot.js +++ b/fastboot.js @@ -53,7 +53,7 @@ let logRequests = morgan( 'at=info method=:method path=":url" ' + 'request_id=:req[x-request-id] ' + 'fwd=":req[x-real-ip]" ' + - 'user_agent=:req[user-agent]', + 'user_agent=":req[user-agent]"', ); let server = new FastBootAppServer({