Skip to content

Commit

Permalink
Support providing node HTTP options to the http server
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Mar 17, 2022
1 parent d6b53b5 commit e6dcec8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/scripts/run/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ export const start = async (cwd: string) => {
console.log(`✅ Admin UI ready`);
}

const port = config.server?.port || process.env.PORT || 3000;
httpServer.listen(port, (err?: any) => {
// use env.PORT if supplied
const port = parseInt(process.env.PORT || '') || config.server?.port;
const options = config.server?.options;
if (options) options.port = port;

httpServer.listen(options ? options : port, (err?: any) => {
if (err) throw err;
console.log(`⭐️ Server Ready on http://localhost:${port}`);
console.log(`⭐️ Server Ready on http://localhost:${options ? options.port : port}`);
});
};
6 changes: 4 additions & 2 deletions packages/core/src/types/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Server } from 'http';
import type { ListenOptions } from 'net';
import type { Config } from 'apollo-server-express';
import { CorsOptions } from 'cors';
import express from 'express';
Expand Down Expand Up @@ -99,10 +100,11 @@ type HealthCheckConfig = {
export type ServerConfig<TypeInfo extends BaseKeystoneTypeInfo> = {
/** Configuration options for the cors middleware. Set to `true` to use core Keystone defaults */
cors?: CorsOptions | true;
/** Port number to start the server on. Defaults to process.env.PORT || 3000 */
port?: number;
/** Maximum upload file size allowed (in bytes) */
maxFileSize?: number;
/** Port number to start the server on. Defaults to process.env.PORT || 3000 */
port?: number;
options?: ListenOptions; // TODO: only .port or .options should be supplied
/** Health check configuration. Set to `true` to add a basic `/_healthcheck` route, or specify the path and data explicitly */
healthCheck?: HealthCheckConfig | true;
/** Hook to extend the Express App that Keystone creates */
Expand Down

0 comments on commit e6dcec8

Please sign in to comment.