Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Feb 28, 2018
1 parent adccd5e commit 1db4217
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 2 additions & 6 deletions app/middleware/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

'use strict';

module.exports = (options, app) => {
let server;
app.once('server', s => {
server = s;
});

module.exports = options => {
return async function meta(ctx, next) {
if (options.logging) {
ctx.coreLogger.info('[meta] request started, host: %s, user-agent: %s', ctx.host, ctx.header['user-agent']);
Expand All @@ -19,6 +14,7 @@ module.exports = (options, app) => {
ctx.set('x-readtime', Date.now() - ctx.starttime);

// try to support Keep-Alive Header
const server = ctx.app.server;
if (server && server.keepAliveTimeout && server.keepAliveTimeout >= 1000 && ctx.header.connection !== 'close') {
const timeout = parseInt(server.keepAliveTimeout / 1000);
ctx.set('keep-alive', `timeout=${timeout}`);
Expand Down
6 changes: 6 additions & 0 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Application extends EggApplication {
options.type = 'application';
super(options);

// will auto set after 'server' event emit
this.server = null;

try {
this.loader.load();
} catch (e) {
Expand Down Expand Up @@ -83,6 +86,9 @@ class Application extends EggApplication {
}

onServer(server) {
// expose app.server
this.server = server;

/* istanbul ignore next */
graceful({
server: [ server ],
Expand Down

0 comments on commit 1db4217

Please sign in to comment.