Message-bus is duplicating headers in Discourse chat

Hello guys

I am trying to understand how works the message-bus feature used by discourse to stay online with new messages and events. Specifically I am insterested in how is used in the recent Discourse chat plugin.

Base in what @sam described in https://meta.discourse.org/t/how-discourse-stays-online-message-bus-faye-long-polling/3238/7?u=jandres, I would like to integrate this functionality along with those that already exist, in my mobile application.

Making some reverse ingeniering I see that when I enter to chatroom, everytime the message-bus make a poll via “https://mysite.com/message-bus/client_id/poll” then the request headers are duplicated for example:
image

So that works into my site but when I try to make a request from an external site or mobile app, then I get the error:

Access to XMLHttpRequest at 'https://forum-dev.srepe.com/message-bus/f6e2303ff7704f608ef2b821fe210e90/poll' 
from origin 'http://localhost:8100' has been blocked by CORS policy: 
The 'Access-Control-Allow-Origin' header contains multiple values 
'https://forum-dev.srepe.com, *', but only one is allowed.

All the others routes are good, but when I try to use the message-bus then this happened. I am using the example @sam leave in the github repository https://github.com/discourse/message_bus/tree/main/examples/chat as source of inspiration.

If you can give me an orientation or a little help with this I will be very grateful :pray:

Thank you very much

1 Like

headers are all set up here:

hopefully that answers this?

Thank you for your quick response.

So, if I understand the message_bus set their own “Headers” ? There are any way to use the “Headers” already set by the config of Discourse, at least those with CORS behaviour ?

I seek to avoid duplicate “headers” when using message_bus. This allow me to make request outside the forum site

You are straying pretty far from a common config, read through that file carefully it should have all the answers

You are right, So if I would use the message_bus from outside the site (like in a PWA or Mobile Hybrid app) what do you advise me.

I would like to use the message_bus as an external client using as example the JavaScript library you already made. https://github.com/discourse/message_bus/tree/main?tab=readme-ov-file#javascript-client

I wonder how this user was able to make it possible.

He publish a youtube video here showing his progress in multiple devices.

There should be a way to user the message_bus gem from outside the discourse site.

Thanks a lot if you can juste guide me a little bit more, or give some idea

I am afraid this is all too custom for me to provide advice here, totally appreciate more people using message bus, but you you are going to have to debug through things here.