You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.
What will happen?
If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect.
If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.
How can I create a reproduction?
We have a couple of templates for starting with a minimal reproduction:
Mixed Content: The page at 'https://local.domain.nl:3000/ild' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://local.domain.nl:24678/_nuxt/'. This request has been blocked; this endpoint must be available over WSS.
client.ts:69 [vite] failed to connect to websocket (SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.).
With #127 (v3.7.3), you can hook into the listen event to register a custom ws handler. Check out this example for usage.
Will be working on some upstream (nitro) fixes to fully unblock devProxy support as well 👍🏼
Thank you @pi0 for the information ! This help me find a workaround
I use multiple Nuxt projects in iframe, in this case HMR does not work at all. @jktantan@ucw maybe can be useful for you and anyone in this case :
import{defineNuxtConfig}from"nuxt/config"import{createProxyServer}from"httpxy"exportdefaultdefineNuxtConfig({nitro: {devProxy: {// Not working"/editor/assets/": {target: "ws://localhost:5003/editor/assets/",ws: true}}},hooks: {// Workaroundlisten(server){constproxy=createProxyServer({target: {host: "localhost",port: 5003}})server.on("upgrade",(req,socket,head)=>{if(req.url==="/editor/assets/"){proxy.ws(req,socket,head)// socket has type error by it works}})}}})
For anybody still having problems with this, I found another workaround which works with the latest nuxt version (3.14.159 currently):
import{defineNuxtModule}from"@nuxt/kit"import{createProxyServer}from"httpxy"// Custom nuxt module for adding websocket proxy support locally. The official support does not work yet,// see https://github.com/nuxt/cli/issues/107 and https://github.com/nuxt/cli/issues/108.exportdefaultdefineNuxtModule({setup(_,nuxt){if(!nuxt.options.dev)return// Take rules from the nitro devProxy configuration that have the ws flag set.constwsProxyRules=Object.entries(nuxt.options.nitro?.devProxy??{}).filter(([,rule])=>typeofrule==="object"&&rule.ws)// We have no rules with websocket proxying, return early.if(!wsProxyRules)return// Create proxy servers for each rule.constproxies=wsProxyRules.map(([key,rule])=>{return[key,createProxyServer(rule)]})nuxt.hook("ready",()=>{// Replace the nuxt server with our own version that uses the configured proxy servers or delegates.nuxt.server={
...nuxt.server,upgrade: (req,socket,head)=>{constproxy=proxies.find(([key])=>req.url.startsWith(key))?.[1]if(proxy){returnproxy.ws(req,socket,{},head)}else{returnnuxt.server.upgrade(req,socket,head)}},}})},})
Add it to e.g. modules/webSocketProxy.js and configure it as if devProxy would be working:
as far as I can tell, a nitro.devProxy entry with ws: true never sees the upgrade: nitro's dev server registers devProxy routes only as HTTP handlers, while NitroDevServer.handleUpgrade forwards unconditionally to the dev worker, so nothing consults ws. HTTP requests to the same path proxy correctly.
testing, the nuxt.server.upgrade workaround from this thread does still work on latest, and the bug still reproduces on nitro v3 so it isn't yet solved
Activity
github-actions commentedon Aug 28, 2023
Would you be able to provide a reproduction? 🙏
More info
Why do I need to provide a reproduction?
Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.
What will happen?
If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect.
If
needs reproductionlabeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.How can I create a reproduction?
We have a couple of templates for starting with a minimal reproduction:
👉 https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
👉 https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox
A public GitHub repository is also perfect. 👌
Please ensure that the reproduction is as minimal as possible. See more details in our guide.
You might also find these other articles interesting and/or helpful:
ucw commentedon Aug 28, 2023
nuxt/nuxt#15417
jktantan commentedon Aug 28, 2023
Interesting, if I downgrade to NUXT 3.6.5, then your code is working. But I try to using your code for NUXT 3.7, that is not working.
ucw commentedon Aug 28, 2023
It seems like this is related to how the new Nuxt CLI works, introduced in Nuxt 3.7. #101
pi0 commentedon Aug 28, 2023
Thanks for the issue. I will be working on a quick solution to make it working again on nuxi 3.7 👍🏼
vanling commentedon Aug 28, 2023
I hope when this is fixed the following works again
{ "name": "domain.nl", "private": true, "scripts": { "dev": "nuxt dev --host local.domain.nl --https --ssl-cert local.domain.nl.pem --ssl-key local.domain.nl-key.pem" } }package.json
pi0 commentedon Aug 28, 2023
host issue is fixed already in latest 3.7.2 cli release. Can you please confirm that? 🙏
vanling commentedon Aug 28, 2023
@pi0 Replacing
nuxt devwithnpx nuxi dev> Still getting the errorMixed Content: The page at 'https://local.domain.nl:3000/ild' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://local.domain.nl:24678/_nuxt/'. This request has been blocked; this endpoint must be available over WSS.client.ts:69 [vite] failed to connect to websocket (SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.).This worked in 3.6.5
jktantan commentedon Aug 28, 2023
Unfortunately, it still doesn't work.
pi0 commentedon Aug 28, 2023
@jktantan I meant the host. WebSocket issue is not resolved yet.
vanling commentedon Aug 28, 2023
@pi0 I will open a new issue to keep things clear here.
pi0 commentedon Aug 30, 2023
With #127 (v3.7.3), you can hook into the
listenevent to register a custom ws handler. Check out this example for usage.Will be working on some upstream (nitro) fixes to fully unblock
devProxysupport as well 👍🏼[-]nuxt3.7 devProxy for websocket not available[/-][+]`nitro.devProxy` for websocket is not working[/+]1 remaining item
jenjen75 commentedon Dec 11, 2023
Thank you @pi0 for the information ! This help me find a workaround
I use multiple Nuxt projects in iframe, in this case HMR does not work at all.
@jktantan @ucw maybe can be useful for you and anyone in this case :
dantio commentedon Jan 28, 2024
@jenjen75 Solution worked for me. Also, this gist can be helpful:
https://gist.github.com/ucw/67f7291c64777fb24341e8eae72bcd24
TimoStolz commentedon Apr 11, 2024
Can we proxy websockets still in Nuxt 3.11 when Nitro's experimental websocket support is enabled? The above workaround is no longer working for me.
emilecaron commentedon Apr 23, 2024
same thing here. workaround was fine before upgrading to 3.11
9M6 commentedon Jul 8, 2024
any news regarding this issue?
danwritecode commentedon Sep 24, 2024
any update on this? this is holding up a production deployment
yochze commentedon Oct 11, 2024
any update on this?
zhaoyuqiqi commentedon Oct 25, 2024
any update on this?
emilecaron commentedon Oct 25, 2024
We eventually switched over to SEE which are working fine. But it won't suit every use case
rubengees commentedon Nov 8, 2024
For anybody still having problems with this, I found another workaround which works with the latest nuxt version (
3.14.159currently):Add it to e.g.
modules/webSocketProxy.jsand configure it as ifdevProxywould be working:danielroe commentedon Jul 25, 2026
would you mind opening an issue upstream in nitro?tracked in nitrojs/nitro#4269
as far as I can tell, a
nitro.devProxyentry withws: truenever sees the upgrade: nitro's dev server registersdevProxyroutes only as HTTP handlers, whileNitroDevServer.handleUpgradeforwards unconditionally to the dev worker, so nothing consultsws. HTTP requests to the same path proxy correctly.testing, the
nuxt.server.upgradeworkaround from this thread does still work on latest, and the bug still reproduces on nitro v3 so it isn't yet solvedcc: @pi0