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

Host on production not working #555

Open
BorisKamp opened this issue Nov 13, 2024 · 1 comment
Open

Host on production not working #555

BorisKamp opened this issue Nov 13, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@BorisKamp
Copy link

Environment

Production

Describe the bug

When I set my clients like this:

      'graphql-client': {
        clients: {
          default: {
            host: '',
            token: process.env.GQL_TOKEN,
            headers: {
              'Content-Type': 'application/json',
            },
          },
          system: {
            host: '',
            token: process.env.GQL_TOKEN,
            headers: {
              'Content-Type': 'application/json',
            },
          },
        },
      },

And have the following env vars in my .env file:

GQL_HOST=http://localhost:8055/graphql
GQL_SYSTEM_HOST=http://localhost:8055/graphql/system

It works great on localhost.

However, when I deploy to production, the GQL client is not defined as the .env vars are not read somehow.

If I do this:

      'graphql-client': {
        clients: {
          default: {
            host: process.env.GQL_HOST ?? 'https://directus-mijn.controlenergy.nl/graphql',
            token: process.env.GQL_TOKEN,
            headers: {
              'Content-Type': 'application/json',
            },
          },
          system: {
            host: process.env.GQL_SYSTEM_HOST ?? 'https://directus-mijn.controlenergy.nl/graphql/system',
            token: process.env.GQL_TOKEN,
            headers: {
              'Content-Type': 'application/json',
            },
          },
        },
      },

It does work on production as there is a default value. But this default value is not overwritten by my server's env var.
The docker-compose.yml I use has these env's:

services:
  cebv-portal-nuxt:
    container_name: ...
    image: ...
    environment:
      - NUXT_PUBLIC_SITE_URL=https://mijn.controlenergy.nl
      - GQL_HOST=https://test.directus-mijn.controlenergy.nl/graphqllllll
      - GQL_SYSTEM_HOST=https://test.directus-mijn.controlenergy.nl/graphql/system
      - .....

But it still uses https://directus-mijn.controlenergy.nl/graphql/system instead of https://test.directus-mijn.controlenergy.nl/graphql/system for example....

@Diizzayy why is this?

Expected behaviour

See above

Reproduction

No response

Additional context

No response

Logs

No response

@BorisKamp BorisKamp added the bug Something isn't working label Nov 13, 2024
@macgyver2k
Copy link

Hi, I just worked arround this problem by setting the environment variable right before the build.

in powershell:

$env:GQL_HOST="http://host.docker.internal:3000/api/graphql"
npm run build

or in Dockerfile:

ENV GQL_HOST=http://host.docker.internal:3000/api/graphql
RUN npm run build

nuxt.config.ts:

runtimeConfig: {
  ...
  public: {
    "graphql-client": {
      clients: {
        default: {
          host: "http://localhost:3000/api/graphql",
          schema: "graphql.schema.json",
          headers: {
            "content-type": "application/json",
          },
        },
      },
    },
  },
  ...
},

This generates the inline runtime config:

const _inlineRuntimeConfig = {
  ...
  "public": {
    "graphql-client": {
      "clients": {
        "default": {
          "token": {
            "type": "Bearer",
            "name": "Authorization"
          },
          "proxyCookies": true,
          "tokenStorage": {
            "mode": "cookie",
            "cookieOptions": {
              "maxAge": 604800,
              "secure": true
            },
            "name": "gql:default"
          },
          "preferGETQueries": false,
          "host": "http://host.docker.internal:3000/api/graphql",
          "schema": "graphql.schema.json",
          "headers": {
            "content-type": "application/json"
          }
        }
      }
    }
  }
  ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants