Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix http server not binding to '::' by default (regression) #8105

Merged
merged 5 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/one-host-binds.md
Original file line number Diff line number Diff line change
@@ -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))
12 changes: 6 additions & 6 deletions packages/core/src/scripts/run/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -285,13 +285,13 @@ 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}`);

const easyHost = httpOptions.host === '::' ? 'localhost' : httpOptions.host;
console.log(
`⭐️ GraphQL API Starting on http://${httpOptions.host}:${httpOptions.port}${
config.graphql?.path || '/api/graphql'
}`
`⭐️ 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
initKeystone().catch(err => {
Expand Down
18 changes: 11 additions & 7 deletions packages/core/src/scripts/run/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,30 @@ export const start = async (cwd: string) => {
console.log(`✅ Admin UI ready`);
}

const options: ListenOptions = {
host: 'localhost',
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 Ready on http://${options.host}:${options.port}`);

const easyHost = httpOptions.host === '::' ? 'localhost' : httpOptions.host;
console.log(
`⭐️ Server listening on ${httpOptions.host}, port ${httpOptions.port} (http://${easyHost}:${httpOptions.port}/)`
);
});
};
56 changes: 28 additions & 28 deletions packages/core/src/scripts/tests/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (http://localhost: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
Expand All @@ -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 (http://localhost: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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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\`
Expand Down Expand Up @@ -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\`
Expand All @@ -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
Expand Down