gotify / server

A simple server for sending and receiving messages in real-time per WebSocket. (Includes a sleek web-ui)
https://gotify.net
Other
11.45k stars 635 forks source link

I am unable to use WebSocket links gotify in web app #730

Open hallejuyahaha opened 6 days ago

hallejuyahaha commented 6 days ago

Have you read the documentation?

You are setting up gotify in

Describe your problem

I am unable to use WebSocket links in web pages: 微信截图_20241111170523

My gotify webui is able to receive messages normally. My Vue JS code looks like this: const token = 'Cj8ZU5BYA9ct8Qc'; const wsUrl = ws://172.96.194.186/stream?token=${token}; this.socket = new WebSocket(wsUrl );

  My server config
    stream:
pingperiodseconds: 45 # the interval in which websocket pings will be sent. Only change this value if you know what you are doing.
allowedorigins: # allowed origins for websocket connections (same origin is always allowed, default only same origin)
  - "159.65.50.159*"   #my web app page server ip
  - "localhost*"

Any errors, logs, or other information that might help us identify your problem

Ex: docker-compose.yml, nginx.conf, android logcat, browser requests, etc.

Name of the information here

contents here

eternal-flame-AD commented 5 days ago

What is the URL of the page you made this screenshot with? The URL of the website before path is the origin required for authentication.

Please try look at the DevTools -> Network page and fine the WebSocket connection request. Make sure the origin header value matches the allowedorigins (the format is Regexp, so don't use the * at the end).

image

Additionally, I have heard about (not a chrome user myself so did not verify) that insecure websocket are disallowed globally in Chrome. You probably should not do them even under a LAN. There will likely be related console messages if this is the case.

hallejuyahaha commented 5 days ago

I specifically used Firefox, and my URL is: I also modified the config.yml: However, the following error still occurs: 我专门使用了firefox,我的url是: image 而且我在config.yml中也修改了: image 但是依然是如下错误: image

eternal-flame-AD commented 5 days ago

The screenshot you shown shows a websocket connection to /ws (likely the auto reload function of development servers or other ws servers), can you find the one that goes to /stream?

It is hard to see what is happening just with this, it would help if you can post a minimal HTML file that reproduce the problem.

jmattheis commented 5 days ago

It's likely https://github.com/gotify/server/issues/372 the cors allowed origins must be configured too.