Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit Heroku-like logs from the Fastboot server #1908

Merged
merged 4 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
13 changes: 12 additions & 1 deletion fastboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -44,16 +46,25 @@ 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) {
Expand Down
1 change: 0 additions & 1 deletion 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 @@ -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",
Expand Down Expand Up @@ -100,6 +100,7 @@
"trailingComma": "all"
},
"dependencies": {
"fastboot-app-server": "^2.0.0"
"fastboot-app-server": "^2.0.0",
"morgan": "^1.9.1"
}
}