rschmied
rschmied
NNuxt
Created by rschmied on 11/24/2024 in #❓・help
devProxy with path both for regular requests and websockets
I am building a GraphQL application where the API endpoint is on /query. I want the devProxy to proxy regular requests AND websocket requests to the same endpoint. However, I can't figure out how to do this properly.
The below obviously doesn't work as is, duplicate key and such:
nitro: {
// https://nitro.unjs.io/config#devproxy
devProxy: {
host: '127.0.0.1',
'/query': {
target: 'http://localhost:8080/query',
changeOrigin: true,
secure: false,
},
'/query': {
target: 'ws://localhost:8080/query',
changeOrigin: true,
secure: false,
ws: true,
},
},
},
nitro: {
// https://nitro.unjs.io/config#devproxy
devProxy: {
host: '127.0.0.1',
'/query': {
target: 'http://localhost:8080/query',
changeOrigin: true,
secure: false,
},
'/query': {
target: 'ws://localhost:8080/query',
changeOrigin: true,
secure: false,
ws: true,
},
},
},
I experimented with creating a separate Nuxt module which handles .on("upgrade") but having the devProxy and some other part of the code handling proxy requests seem to interfere which each other. And no, I don't want to change the server / GraphQL logic. It works all fine when running outside the dev environment. Module based on this. Is there a canonical / supported way to do what I have in mind? This uses 3.15.0 for Nuxt and I guess there's no easy way to reproduce this as it requires a functional back-end. FWIW, this used to work when Nuxt was using node-http-proxy where the signature for ws was proxy.ws(req, socket, head) E.g. the options weren't passed in as the 3rd arg. Thanks!
8 replies