Skip to content

Commit f2f7eb9

Browse files
feat: add new env vars
1 parent 267ce43 commit f2f7eb9

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

docs/pages/product/configuration/reference/environment-variables.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,26 @@ Until v0.35, the default value was `schema`.
11281128
It can be also set using the [`schema_path` configuration
11291129
option](/product/configuration/reference/config#schema_path).
11301130

1131+
## `CUBEJS_SERVER_HEADERS_TIMEOUT`
1132+
1133+
The number of milliseconds to limit the amount of time the parser will wait
1134+
to receive the complete HTTP headers.
1135+
If the timeout expires, the server responds with status 408 without
1136+
forwarding the request to the request listener and then closes the connection.
1137+
1138+
| Possible Values | Default in Development | Default in Production |
1139+
| ----------------------------------------- | ------------------------ | ------------------------ |
1140+
| A valid number or string representing one | NodeJS's version default | NodeJS's version default |
1141+
1142+
## `CUBEJS_SERVER_KEEP_ALIVE_TIMEOUT`
1143+
1144+
The number of milliseconds of inactivity a server needs to wait for additional incoming data,
1145+
after it has finished writing the last response, before a socket will be destroyed.
1146+
1147+
| Possible Values | Default in Development | Default in Production |
1148+
| ----------------------------------------- | ------------------------ | ------------------------ |
1149+
| A valid number or string representing one | NodeJS's version default | NodeJS's version default |
1150+
11311151
## `CUBEJS_SQL_USER`
11321152

11331153
A username required to access the [SQL API][ref-sql-api].

packages/cubejs-backend-shared/src/env.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ const variables: Record<string, (...args: any) => any> = {
144144
webSockets: () => get('CUBEJS_WEB_SOCKETS')
145145
.default('false')
146146
.asBoolStrict(),
147+
serverHeadersTimeout: () => get('CUBEJS_SERVER_HEADERS_TIMEOUT')
148+
.asInt(),
149+
serverKeepAliveTimeout: () => get('CUBEJS_SERVER_KEEP_ALIVE_TIMEOUT')
150+
.asInt(),
147151
rollupOnlyMode: () => get('CUBEJS_ROLLUP_ONLY')
148152
.default('false')
149153
.asBoolStrict(),

packages/cubejs-server/src/server.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type RequireOne<T, K extends keyof T> = {
4747
export class CubejsServer {
4848
protected readonly core: CubeCore;
4949

50-
protected readonly config: RequireOne<CreateOptions, 'webSockets' | 'http' | 'sqlPort' | 'pgSqlPort'>;
50+
protected readonly config: RequireOne<CreateOptions, 'webSockets' | 'http' | 'sqlPort' | 'pgSqlPort' | 'serverHeadersTimeout' | 'serverKeepAliveTimeout'>;
5151

5252
protected server: GracefulHttpServer | null = null;
5353

@@ -64,6 +64,8 @@ export class CubejsServer {
6464
sqlPort: config.sqlPort || getEnv('sqlPort'),
6565
pgSqlPort: config.pgSqlPort || getEnv('pgSqlPort'),
6666
gatewayPort: config.gatewayPort || getEnv('nativeApiGatewayPort'),
67+
serverHeadersTimeout: config.serverHeadersTimeout ?? getEnv('serverHeadersTimeout'),
68+
serverKeepAliveTimeout: config.serverKeepAliveTimeout ?? getEnv('serverKeepAliveTimeout'),
6769
http: {
6870
...config.http,
6971
cors: {
@@ -114,6 +116,14 @@ export class CubejsServer {
114116
await this.sqlServer.init(this.config);
115117
}
116118

119+
if (this.config.serverKeepAliveTimeout) {
120+
this.server.keepAliveTimeout = this.config.serverKeepAliveTimeout;
121+
}
122+
123+
if (this.config.serverHeadersTimeout) {
124+
this.server.headersTimeout = this.config.serverHeadersTimeout;
125+
}
126+
117127
const PORT = getEnv('port');
118128
await this.server.listen(PORT);
119129

0 commit comments

Comments
 (0)