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

Relative API Endpoint #580

Open
IgorKha opened this issue Dec 17, 2024 · 0 comments
Open

Relative API Endpoint #580

IgorKha opened this issue Dec 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@IgorKha
Copy link

IgorKha commented Dec 17, 2024

Environment

------------------------------
- Operating System: Darwin
- Node Version:     v20.9.0
- Nuxt Version:     3.12.4
- CLI Version:      3.12.0
- Nitro Version:    2.9.7
- Package Manager:  [email protected]
- Builder:          -
- User Config:      devtools, modules, pinia, runtimeConfig, graphql-client, nitro, ssr, routeRules, ui, colorMode, components, compatibilityDate
- Runtime Modules:  @pinia/[email protected], [email protected], @pinia-plugin-persistedstate/[email protected], @nuxt/[email protected]
- Build Modules:    -
------------------------------
import { existsSync } from 'fs'

const schemaPath = './schema.graphql'
const schema = existsSync(schemaPath) ? schemaPath : undefined

export default defineNuxtConfig({
  modules: [
    'nuxt-graphql-client',
    ...
  ]
...
  'graphql-client': {
      clients: {
        default: {
          host: '/api/gql',
          schema
        },
      },
    },

  nitro: {
    routeRules: {
      '/api/gql': { proxy: 'http://127.0.0.1:4000/api/gql' },
    }
  },

...

Describe the bug

Hi, I'm not sure if this is a bug, but if not, I need some help understanding what's happening. I want to make my API endpoint relative because I don't have a static hostname on my devices, and it can change depending on the IP assigned to the device.

  1. When proxying through Nitro with host: '/api/gql' (calling the API via frontend proxying), I receive responses in Insomnia. This leads me to believe that such an approach works.
  2. However, when I try to use nuxt-graphql-client on the frontend, I don't see any requests in the browser at all.
  3. In the same scenario as point 2, but using host: 'http://192.168.1.10:4000/api/gql' (hardcoding the backend's IP and port), everything works fine.

Expected behaviour

I expect relative paths to work the same way as full paths.

Thank you!

Reproduction

No response

Additional context

No response

Logs

No response

@IgorKha IgorKha added the bug Something isn't working label Dec 17, 2024
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

1 participant