Skip to content

Commit

Permalink
refactor(core-api): use shorter default timeouts (#3804)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiodf authored Jun 17, 2020
1 parent 09e0892 commit f4025bb
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions __tests__/unit/core-api/plugins/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe("Cache", () => {
pagination: {
limit: 100,
},
socketTimeout: 5000,
cache: {
enabled: true,
stdTTL: 0, // unlimited
Expand Down
1 change: 1 addition & 0 deletions __tests__/unit/core-api/plugins/hapi-ajv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("Hapi Ajv", () => {
pagination: {
limit: 100,
},
socketTimeout: 5000,
cache: {
enabled: true,
stdTTL: 0, // unlimited
Expand Down
1 change: 1 addition & 0 deletions __tests__/unit/core-api/plugins/pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe("Pagination", () => {
pagination: {
limit: 100,
},
socketTimeout: 5000,
},
};

Expand Down
1 change: 1 addition & 0 deletions __tests__/unit/core-api/plugins/rate-limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("Rate limit", () => {
pagination: {
limit: 100,
},
socketTimeout: 5000,
rateLimit: {
enabled: true,
points: 1,
Expand Down
1 change: 1 addition & 0 deletions __tests__/unit/core-api/plugins/whitelist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe("Whitelist", () => {
pagination: {
limit: 100,
},
socketTimeout: 5000,
whitelist: ["127.0.0.1"],
},
};
Expand Down
1 change: 1 addition & 0 deletions __tests__/unit/core-api/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("Server", () => {
pagination: {
limit: 100,
},
socketTimeout: 5000,
whitelist: ["*"],
},
};
Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const defaults = {
pagination: {
limit: 100,
},
socketTimeout: 5000,
whitelist: ["*"],
},
options: {
Expand Down
6 changes: 6 additions & 0 deletions packages/core-api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export class Server {
public async initialize(name: string, optionsServer: Types.JsonObject): Promise<void> {
this.name = name;
this.server = new HapiServer(this.getServerOptions(optionsServer));

const timeout: number = this.configuration.getRequired<number>("plugins.socketTimeout");
this.server.listener.timeout = timeout;
this.server.listener.keepAliveTimeout = timeout;
this.server.listener.headersTimeout = timeout;

this.server.app.app = this.app;
this.server.app.schemas = createSchemas({
pagination: {
Expand Down

0 comments on commit f4025bb

Please sign in to comment.