From c513b70b468f27c352587fbb2d861607ff14bcf1 Mon Sep 17 00:00:00 2001 From: "David R. Myers" Date: Thu, 5 Oct 2023 13:47:12 -0400 Subject: [PATCH] Use 127.0.0.1 instead of localhost - https://github.com/cypress-io/cypress/issues/26154 - https://github.com/node-fetch/node-fetch/issues/1624 - https://github.com/nodejs/node/issues/40702 --- .env.example | 10 +++++----- .github/workflows/ci.yml | 12 ++++++------ CONTRIBUTING.md | 4 ++-- cypress.config.ts | 2 +- nuxt.config.ts | 3 +++ src/firebase.js | 8 ++++---- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.env.example b/.env.example index fabf584f..0f265593 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -CYPRESS_BASE_URL=http://localhost:8888 +CYPRESS_BASE_URL=http://127.0.0.1:8888 FIREBASE_PROJECT_ID=demo-octo FIREBASE_TOKEN=fake NUXT_PUBLIC_CDN_URL= @@ -19,13 +19,13 @@ NUXT_PUBLIC_FIREBASE_APP_ID=fake NUXT_PUBLIC_FIREBASE_AUTH_DOMAIN=fake NUXT_PUBLIC_FIREBASE_DATABASE_URL=fake NUXT_PUBLIC_FIREBASE_DISABLED=1 -NUXT_PUBLIC_FIREBASE_EMULATOR_AUTH=http://localhost:32775 +NUXT_PUBLIC_FIREBASE_EMULATOR_AUTH=http://127.0.0.1:32775 NUXT_PUBLIC_FIREBASE_EMULATOR_BYPASS= -NUXT_PUBLIC_FIREBASE_EMULATOR_FIRESTORE_HOST=localhost +NUXT_PUBLIC_FIREBASE_EMULATOR_FIRESTORE_HOST=127.0.0.1 NUXT_PUBLIC_FIREBASE_EMULATOR_FIRESTORE_PORT=32776 -NUXT_PUBLIC_FIREBASE_EMULATOR_FUNCTIONS_HOST=localhost +NUXT_PUBLIC_FIREBASE_EMULATOR_FUNCTIONS_HOST=127.0.0.1 NUXT_PUBLIC_FIREBASE_EMULATOR_FUNCTIONS_PORT=32779 -NUXT_PUBLIC_FIREBASE_EMULATOR_STORAGE_HOST=localhost +NUXT_PUBLIC_FIREBASE_EMULATOR_STORAGE_HOST=127.0.0.1 NUXT_PUBLIC_FIREBASE_EMULATOR_STORAGE_PORT=32778 NUXT_PUBLIC_FIREBASE_LOG_LEVEL= NUXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=fake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c484a72..cbf77d83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,13 +25,13 @@ env: NUXT_PUBLIC_FIREBASE_AUTH_DOMAIN: fake NUXT_PUBLIC_FIREBASE_DATABASE_URL: fake NUXT_PUBLIC_FIREBASE_DISABLED: - NUXT_PUBLIC_FIREBASE_EMULATOR_AUTH: http://localhost:32775 + NUXT_PUBLIC_FIREBASE_EMULATOR_AUTH: http://127.0.0.1:32775 NUXT_PUBLIC_FIREBASE_EMULATOR_BYPASS: - NUXT_PUBLIC_FIREBASE_EMULATOR_FIRESTORE_HOST: localhost + NUXT_PUBLIC_FIREBASE_EMULATOR_FIRESTORE_HOST: 127.0.0.1 NUXT_PUBLIC_FIREBASE_EMULATOR_FIRESTORE_PORT: 32776 - NUXT_PUBLIC_FIREBASE_EMULATOR_FUNCTIONS_HOST: localhost + NUXT_PUBLIC_FIREBASE_EMULATOR_FUNCTIONS_HOST: 127.0.0.1 NUXT_PUBLIC_FIREBASE_EMULATOR_FUNCTIONS_PORT: 32779 - NUXT_PUBLIC_FIREBASE_EMULATOR_STORAGE_HOST: localhost + NUXT_PUBLIC_FIREBASE_EMULATOR_STORAGE_HOST: 127.0.0.1 NUXT_PUBLIC_FIREBASE_EMULATOR_STORAGE_PORT: 32778 NUXT_PUBLIC_FIREBASE_LOG_LEVEL: debug NUXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: fake @@ -132,12 +132,12 @@ jobs: - uses: cypress-io/github-action@v6.5.0 with: build: pnpm build - config: baseUrl=http://localhost:8889 + config: baseUrl=http://127.0.0.1:8889 install: false start: | pnpm firebase:start pnpm preview - wait-on: 'http://localhost:8889,http://localhost:32777' + wait-on: 'http://127.0.0.1:8889,http://127.0.0.1:32777' - uses: actions/upload-artifact@v3 if: failure() with: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8545999c..676b2a65 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -54,7 +54,7 @@ cp .env.example .env Run the app in `development` mode. ```bash -# binds to localhost:8888 +# binds to 127.0.0.1:8888 pnpm dev ``` @@ -80,6 +80,6 @@ The build output will be available in the `.output` directory. ### Run the `production` preview ```bash -# binds to localhost:8889 +# binds to 127.0.0.1:8889 pnpm preview ``` diff --git a/cypress.config.ts b/cypress.config.ts index 9dfd4e74..a79efc6a 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -3,7 +3,7 @@ import { defineConfig } from 'cypress' export default defineConfig({ downloadsFolder: 'test/cypress/downloads', e2e: { - baseUrl: 'http://localhost:8888', + baseUrl: 'http://127.0.0.1:8888', modifyObstructiveCode: false, specPattern: 'test/cypress/e2e/**/*.cy.{ts,tsx}', supportFile: 'test/cypress/support/e2e.{ts,tsx}', diff --git a/nuxt.config.ts b/nuxt.config.ts index 4d2a3c40..d30d4c42 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -66,6 +66,9 @@ export default defineNuxtConfig({ 'rxjs', ], }, + devServer: { + host: '127.0.0.1', + }, experimental: { // Todo: Does not respect port provided with `nuxi dev --port` // viteNode: true, diff --git a/src/firebase.js b/src/firebase.js index 78d291af..22fd6e88 100644 --- a/src/firebase.js +++ b/src/firebase.js @@ -31,25 +31,25 @@ export const init = () => { storageBucket: publicConfig.firebaseStorageBucket, } - if (!verifyConfig(config)) { return } + if (!verifyConfig(config)) return // init firebase const app = initializeApp(config) initializeFirestore(app, { - experimentalAutoDetectLongPolling: true + experimentalAutoDetectLongPolling: true, }) setLogLevel(publicConfig.firebaseLogLevel || 'error') // use emulators in development - if (location.hostname === 'localhost' && !publicConfig.firebaseEmulatorBypass) { + if (['localhost', '127.0.0.1'].includes(location.hostname) && !publicConfig.firebaseEmulatorBypass) { connectAuthEmulator( getAuth(), publicConfig.firebaseEmulatorAuth, { disableWarnings: true, - } + }, ) connectFirestoreEmulator(