Skip to content

Commit

Permalink
feat: allow to track server timings
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-drexler authored and dmbch committed Mar 12, 2018
1 parent 3b29a96 commit 31ee6ad
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 24 deletions.
1 change: 1 addition & 0 deletions packages/build/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ process.on('unhandledRejection', function(error) {
function runDevelop(options, callback) {
var compiler = webpack(developConfig);
var app = express();
app.use(hopsExpressUtils.timings);
app.use(
webpackDevMiddleware(compiler, {
noInfo: true,
Expand Down
44 changes: 22 additions & 22 deletions packages/config/README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function applyDefaultConfig(config) {
assetPath: '',
workerPath: '<basePath>/sw.js',
workerFile: null,
enableServerTimings: true,
browsers: '> 1%, last 2 versions, Firefox ESR',
node: 'current',
envVars: { HOPS_MODE: 'dynamic' },
Expand Down
1 change: 1 addition & 0 deletions packages/express/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var swRe = new RegExp(hopsConfig.workerPath + '$');

function createApp(options) {
var app = express();
app.use(utils.timings);
app.use(helmet());
app.use(compression());
app.use(utils.rewritePath);
Expand Down
7 changes: 7 additions & 0 deletions packages/express/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ exports.assetsMiddleware = function assetsMiddleware(req, res, next) {
next();
};

exports.timings = hopsConfig.enableServerTimings
? require('server-timings')
: function(req, res, next) {
res.locals.timings = { start: function() {}, end: function() {} };
next();
};

exports.bootstrap = hopsConfig.bootstrapServer || function() {};

exports.teardown = hopsConfig.teardownServer || function() {};
3 changes: 2 additions & 1 deletion packages/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"express": "^4.16.0",
"helmet": "^3.8.2",
"hops-config": "10.2.0-rc.0",
"mime": "^2.2.0"
"mime": "^2.2.0",
"server-timings": "^2.0.1"
}
}
1 change: 1 addition & 0 deletions packages/spec/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('config', function() {
buildDir: path.resolve('build'),
cacheDir: path.resolve(path.join('node_modules', '.cache', 'hops')),
workerFile: null,
enableServerTimings: true,
workerPath: '/sw.js',
});
});
Expand Down
8 changes: 7 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5578,7 +5578,7 @@ on-finished@~2.3.0:
dependencies:
ee-first "1.1.1"

on-headers@~1.0.1:
on-headers@^1.0.1, on-headers@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/on-headers/-/on-headers-1.0.1.tgz#928f5d0f470d49342651ea6794b0857c100693f7"

Expand Down Expand Up @@ -7223,6 +7223,12 @@ serve-static@1.13.1:
parseurl "~1.3.2"
send "0.16.1"

server-timings@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/server-timings/-/server-timings-2.0.1.tgz#77b9febc1fab102d1b2c5dc8838767780d0c7c93"
dependencies:
on-headers "^1.0.1"

serverless-http@^1.5.2:
version "1.5.3"
resolved "https://registry.yarnpkg.com/serverless-http/-/serverless-http-1.5.3.tgz#86b695a354a7780715672291cc5c1f5fc6bcff2e"
Expand Down

0 comments on commit 31ee6ad

Please sign in to comment.