Cross-Origin Request : MQTT external access

Website URL

http://peplegal.kesug.com/

Error Message

Connection status update: MQTT Error: NetworkError when attempting to fetch resource., error, mode: cloud, mqtt: false, ws: false, http: false

Other Information

The javascript script is trying to access test.mosquito.org to retrieve operational data and that is not working.

Hello, and welcome to the InfinityFree Forum!

Based on the Console, there are some missing files, which may be causing this issue.

I see that the site is constantly calling files in a timed manner. If the files were uploaded, you would reach the Hits Limit quickly.

If those files were uploaded, but they are now missing, it could be due to the File Size Limits:


Either this does not exist, or my network does not trust displaying this.


1 Like

Thank you so much for your fast response ! That was really appreciated.

I managed to reduce the amount of browser errors…but still there is a persistent error :

The javascript in the page is trying to connect to a public (and free) MQTT broker at test.mosquitto.org

(sorry for the typo in my previous post)

I’m not aware if that broker allows cross-origin requests…or how to enable it. I’m deep searching on Internet and also asking some AI Bots…but no decent answer so far.

From the error message alone, it appears that your website is requesting a non-existent resource. If you look closely at the error message, you can see that it mentions 404 as a status code. Any request that points to a non-existent resource is redirected to the default 404 page (i.e: https://errors.infinityfree.net/errors/404), unless you change it into something else using .htaccess. Since the origin of the error page does not allow CORS by default, any external request that is going to be made on the origin is blocked by the browser. That’s why an error about CORS is being emitted. However, it is not the main problem here; it is the 404 problem. You should ignore the CORS problem and focus on finding out which resource is missing on your server.

7 Likes

I inspected your website and found out that the website’s favicon was missing. It was the culprit behind the error. You can either ignore it if you don’t care about website icon or take action about it. I do not think it is related to the broker at all.

6 Likes

According to its documentation, the broker allows cross-origin requests through the communication of websockets. Even though it does not explicitly states that it allows cross-origin requests, if it allows connections through websockets in public manner, then it is being implied that they also allow cross-origin requests since it is impossible for them to provide websockets for the unauthenticated clients without allowing CORS in the first place.

Rather than asking whether or not the broker allows CORS, you should ask about the “rules” for abiding CORS. Unfortunately, we have limited knowledge about the MQTT broker so we can’t help you in this matter.


I don’t think it is Infinityfree’s fault. Take note that Infinityfree allows any connection to the websockets from external sources, as long as you don’t host your own websocket server and connect into that server.

You can conduct experiments in your machine to test whether or not MQTT test service allows cross-origin requests. If you can connect into its websocket locally, then that means it allows cross-origin requests.

5 Likes

If you’re trying to establish a connection to MQTT (or any other service for that matter) from your website’s Javascript code, that process is entirely between your code and that service. The connection doesn’t go through our servers, so there is nothing we can really do to make it work or not work.

When I check your website, I see the following error in the console:

MQTT Connection failed:
Object { invocationContext: undefined, errorCode: 6, errorMessage: “AMQJS0006E Bad Connack return code:5 Connection Refused: not authorized.” }

This seems like a pretty clear issue with the MQTT connection you can work on. A quick Google search suggests that it might be caused by invalid credentials, but I don’t really know enough about MQTT to really help you with this.

The CORS error on our 404 page is definitely not the issue.

6 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.