From f2c97332ae86aff1e87bdec090f5e6433079a6a7 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 21 Nov 2022 12:02:14 +1100 Subject: [PATCH 1/5] fix httpServer interface binding --- packages/core/src/scripts/run/dev.ts | 2 +- packages/core/src/scripts/run/start.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/scripts/run/dev.ts b/packages/core/src/scripts/run/dev.ts index ed78928375f..d9d15613655 100644 --- a/packages/core/src/scripts/run/dev.ts +++ b/packages/core/src/scripts/run/dev.ts @@ -266,7 +266,7 @@ export const dev = async (cwd: string, shouldDropDatabase: boolean) => { }); const httpOptions: ListenOptions = { - host: 'localhost', + host: '::', // the default for nodejs httpServer port: 3000, }; diff --git a/packages/core/src/scripts/run/start.ts b/packages/core/src/scripts/run/start.ts index 2c97056bb93..397f2e8b8c6 100644 --- a/packages/core/src/scripts/run/start.ts +++ b/packages/core/src/scripts/run/start.ts @@ -42,7 +42,7 @@ export const start = async (cwd: string) => { } const options: ListenOptions = { - host: 'localhost', + host: '::', // the default for nodejs httpServer port: 3000, }; From 42bcfe3279717fd6870e2140d6f7a4d1a1208955 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 21 Nov 2022 12:05:24 +1100 Subject: [PATCH 2/5] add changeset --- .changeset/one-host-binds.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/one-host-binds.md diff --git a/.changeset/one-host-binds.md b/.changeset/one-host-binds.md new file mode 100644 index 00000000000..9ee49e982cb --- /dev/null +++ b/.changeset/one-host-binds.md @@ -0,0 +1,5 @@ +--- +'@keystone-6/core': patch +--- + +Fix `http` server not binding to '::' by default (regression introduced by [#8078](https://github.com/keystonejs/keystone/pull/8078)) From e101b66b5579abf61b820a1d32617e52ca395322 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 21 Nov 2022 12:28:31 +1100 Subject: [PATCH 3/5] update logging copy, drop the http url --- packages/core/src/scripts/run/dev.ts | 9 +++------ packages/core/src/scripts/run/start.ts | 2 +- packages/core/src/scripts/tests/migrations.test.ts | 8 ++++---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/core/src/scripts/run/dev.ts b/packages/core/src/scripts/run/dev.ts index d9d15613655..fff2ec56630 100644 --- a/packages/core/src/scripts/run/dev.ts +++ b/packages/core/src/scripts/run/dev.ts @@ -286,12 +286,9 @@ export const dev = async (cwd: string, shouldDropDatabase: boolean) => { const server = httpServer.listen(httpOptions, (err?: any) => { if (err) throw err; // We start initialising Keystone after the dev server is ready, - console.log(`⭐️ Dev Server Starting on http://${httpOptions.host}:${httpOptions.port}`); - console.log( - `⭐️ GraphQL API Starting on http://${httpOptions.host}:${httpOptions.port}${ - config.graphql?.path || '/api/graphql' - }` - ); + console.log(`⭐️ Server listening on ${httpOptions.host}, port ${httpOptions.port}`); + console.log(`⭐️ GraphQL API available at ${config.graphql?.path || '/api/graphql' }`); + // Don't start initialising Keystone until the dev server is ready, // otherwise it slows down the first response significantly initKeystone().catch(err => { diff --git a/packages/core/src/scripts/run/start.ts b/packages/core/src/scripts/run/start.ts index 397f2e8b8c6..dd51fc48d09 100644 --- a/packages/core/src/scripts/run/start.ts +++ b/packages/core/src/scripts/run/start.ts @@ -61,6 +61,6 @@ export const start = async (cwd: string) => { httpServer.listen(options, (err?: any) => { if (err) throw err; - console.log(`⭐️ Server Ready on http://${options.host}:${options.port}`); + console.log(`⭐️ Server listening on ${options.host}, port ${options.port}`); }); }; diff --git a/packages/core/src/scripts/tests/migrations.test.ts b/packages/core/src/scripts/tests/migrations.test.ts index 8daabe8953a..935d50dfd5e 100644 --- a/packages/core/src/scripts/tests/migrations.test.ts +++ b/packages/core/src/scripts/tests/migrations.test.ts @@ -86,8 +86,8 @@ model Todo { `); expect(recording()).toEqual(`✨ Starting Keystone -⭐️ Dev Server Starting on http://localhost:3000 -⭐️ GraphQL API Starting on http://localhost:3000/api/graphql +⭐️ Server listening on ::, port 3000 +⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ sqlite database "app.db" created at file:./app.db ✨ Your database is now in sync with your schema. Done in 0ms @@ -109,8 +109,8 @@ describe('useMigrations: false', () => { expect(recording()).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ The database is already in sync with the Prisma schema. ✨ Connecting to the database From a7a966560ef1d2852c0caaee88587046e35c26d4 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 21 Nov 2022 12:34:48 +1100 Subject: [PATCH 4/5] restore the easy url --- packages/core/src/scripts/run/dev.ts | 9 ++++++--- packages/core/src/scripts/run/start.ts | 16 ++++++++++------ .../core/src/scripts/tests/migrations.test.ts | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/core/src/scripts/run/dev.ts b/packages/core/src/scripts/run/dev.ts index fff2ec56630..82f4fb4ce7d 100644 --- a/packages/core/src/scripts/run/dev.ts +++ b/packages/core/src/scripts/run/dev.ts @@ -285,9 +285,12 @@ export const dev = async (cwd: string, shouldDropDatabase: boolean) => { const server = httpServer.listen(httpOptions, (err?: any) => { if (err) throw err; - // We start initialising Keystone after the dev server is ready, - console.log(`⭐️ Server listening on ${httpOptions.host}, port ${httpOptions.port}`); - console.log(`⭐️ GraphQL API available at ${config.graphql?.path || '/api/graphql' }`); + + const easyHost = httpOptions.host === '::' ? 'localhost' : httpOptions.host; + console.log( + `⭐️ Server listening on ${httpOptions.host}, port ${httpOptions.port} (http://${easyHost}:${httpOptions.port})` + ); + console.log(`⭐️ GraphQL API available at ${config.graphql?.path || '/api/graphql'}`); // Don't start initialising Keystone until the dev server is ready, // otherwise it slows down the first response significantly diff --git a/packages/core/src/scripts/run/start.ts b/packages/core/src/scripts/run/start.ts index dd51fc48d09..a678f0a77a9 100644 --- a/packages/core/src/scripts/run/start.ts +++ b/packages/core/src/scripts/run/start.ts @@ -41,26 +41,30 @@ export const start = async (cwd: string) => { console.log(`✅ Admin UI ready`); } - const options: ListenOptions = { + const httpOptions: ListenOptions = { host: '::', // the default for nodejs httpServer port: 3000, }; if (config?.server && 'port' in config.server) { - options.port = config.server.port; + httpOptions.port = config.server.port; } if (config?.server && 'options' in config.server && config.server.options) { - Object.assign(options, config.server.options); + Object.assign(httpOptions, config.server.options); } // preference env.PORT if supplied if ('PORT' in process.env) { - options.port = parseInt(process.env.PORT || ''); + httpOptions.port = parseInt(process.env.PORT || ''); } - httpServer.listen(options, (err?: any) => { + httpServer.listen(httpOptions, (err?: any) => { if (err) throw err; - console.log(`⭐️ Server listening on ${options.host}, port ${options.port}`); + + const easyHost = httpOptions.host === '::' ? 'localhost' : httpOptions.host; + console.log( + `⭐️ Server listening on ${httpOptions.host}, port ${httpOptions.port} (http://${easyHost}:${httpOptions.port})` + ); }); }; diff --git a/packages/core/src/scripts/tests/migrations.test.ts b/packages/core/src/scripts/tests/migrations.test.ts index 935d50dfd5e..31a7a49a9f2 100644 --- a/packages/core/src/scripts/tests/migrations.test.ts +++ b/packages/core/src/scripts/tests/migrations.test.ts @@ -86,7 +86,7 @@ model Todo { `); expect(recording()).toEqual(`✨ Starting Keystone -⭐️ Server listening on ::, port 3000 +⭐️ Server listening on ::, port 3000 (http://localhost:3000/) ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ sqlite database "app.db" created at file:./app.db @@ -109,7 +109,7 @@ describe('useMigrations: false', () => { expect(recording()).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Server listening on ::, port 3000 + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ The database is already in sync with the Prisma schema. From ca40242fb79a38b4df94146971d8e2c9641bbb90 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 21 Nov 2022 12:50:05 +1100 Subject: [PATCH 5/5] fix unit tests --- packages/core/src/scripts/run/dev.ts | 2 +- packages/core/src/scripts/run/start.ts | 2 +- .../core/src/scripts/tests/migrations.test.ts | 48 +++++++++---------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/core/src/scripts/run/dev.ts b/packages/core/src/scripts/run/dev.ts index 82f4fb4ce7d..99168dfa06c 100644 --- a/packages/core/src/scripts/run/dev.ts +++ b/packages/core/src/scripts/run/dev.ts @@ -288,7 +288,7 @@ export const dev = async (cwd: string, shouldDropDatabase: boolean) => { const easyHost = httpOptions.host === '::' ? 'localhost' : httpOptions.host; console.log( - `⭐️ Server listening on ${httpOptions.host}, port ${httpOptions.port} (http://${easyHost}:${httpOptions.port})` + `⭐️ Server listening on ${httpOptions.host}, port ${httpOptions.port} (http://${easyHost}:${httpOptions.port}/)` ); console.log(`⭐️ GraphQL API available at ${config.graphql?.path || '/api/graphql'}`); diff --git a/packages/core/src/scripts/run/start.ts b/packages/core/src/scripts/run/start.ts index a678f0a77a9..a3e7d760134 100644 --- a/packages/core/src/scripts/run/start.ts +++ b/packages/core/src/scripts/run/start.ts @@ -64,7 +64,7 @@ export const start = async (cwd: string) => { const easyHost = httpOptions.host === '::' ? 'localhost' : httpOptions.host; console.log( - `⭐️ Server listening on ${httpOptions.host}, port ${httpOptions.port} (http://${easyHost}:${httpOptions.port})` + `⭐️ Server listening on ${httpOptions.host}, port ${httpOptions.port} (http://${easyHost}:${httpOptions.port}/)` ); }); }; diff --git a/packages/core/src/scripts/tests/migrations.test.ts b/packages/core/src/scripts/tests/migrations.test.ts index 31a7a49a9f2..b90ace6c2d3 100644 --- a/packages/core/src/scripts/tests/migrations.test.ts +++ b/packages/core/src/scripts/tests/migrations.test.ts @@ -146,8 +146,8 @@ describe('useMigrations: false', () => { `); expect(recording()).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ⚠️ Warnings: @@ -189,8 +189,8 @@ describe('useMigrations: false', () => { `); expect(recording()).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ⚠️ Warnings: @@ -217,8 +217,8 @@ describe('useMigrations: false', () => { expect(recording()).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ Your database has been reset ✨ Your database is now in sync with your schema. Done in 0ms @@ -265,8 +265,8 @@ CREATE TABLE "Todo" ( `); expect(cleanOutputForApplyingMigration(recording(), migrationName)).toEqual(`✨ Starting Keystone -⭐️ Dev Server Starting on http://localhost:3000 -⭐️ GraphQL API Starting on http://localhost:3000/api/graphql +⭐️ Server listening on ::, port 3000 (http://localhost:3000/) +⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ sqlite database "app.db" created at file:./app.db ✨ There has been a change to your Keystone schema that requires a migration @@ -339,8 +339,8 @@ describe('useMigrations: true', () => { expect(cleanOutputForApplyingMigration(recording(), migrationName)).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ There has been a change to your Keystone schema that requires a migration @@ -412,8 +412,8 @@ describe('useMigrations: true', () => { expect(cleanOutputForApplyingMigration(recording(), migrationName)).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ There has been a change to your Keystone schema that requires a migration @@ -476,8 +476,8 @@ describe('useMigrations: true', () => { ) ).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas - Drift detected: Your database schema is not in sync with your migration history. @@ -524,8 +524,8 @@ describe('useMigrations: true', () => { expect(recording().replace(oldMigrationName, 'old_migration_name')).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas - Drift detected: Your database schema is not in sync with your migration history. @@ -596,8 +596,8 @@ describe('useMigrations: true', () => { expect(recording().replace(migrationName!, 'migration_name')).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ There has been a change to your Keystone schema that requires a migration @@ -636,8 +636,8 @@ describe('useMigrations: true', () => { expect(recording().replace(new RegExp(migrationName, 'g'), 'migration_name')) .toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ sqlite database "app.db" created at file:./app.db Applying migration \`migration_name\` @@ -672,8 +672,8 @@ describe('useMigrations: true', () => { expect(recording().replace(new RegExp(migrationName, 'g'), 'migration_name')) .toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ Your database has been reset Applying migration \`migration_name\` @@ -695,8 +695,8 @@ describe('useMigrations: true', () => { expect(recording()).toMatchInlineSnapshot(` "✨ Starting Keystone - ⭐️ Dev Server Starting on http://localhost:3000 - ⭐️ GraphQL API Starting on http://localhost:3000/api/graphql + ⭐️ Server listening on ::, port 3000 (http://localhost:3000/) + ⭐️ GraphQL API available at /api/graphql ✨ Generating GraphQL and Prisma schemas ✨ Your database is up to date, no migrations need to be created or applied ✨ Connecting to the database