3

I've set up a new dev environment with Nginx as reverse proxy using self signed certificates and a Mosquitto MQTT broker.

I have a NestJS backend using MQTT with following configuration:

private readonly connection = mqtt.connectAsync('wss://mqtt-ssl.test.duckdns.org:9001', {
    username: 'local',
    password: '12345',
    clientId: "backend",
    rejectUnauthorized: false, //self signed
});

It immediately connects to the Mosquitto broker running in a docker container.

the angular 20 frontend with same configuration fails to connect to the broker:

export const MQTT_SERVICE_OPTIONS: IMqttServiceOptions = {
    url: "wss://mqtt-ssl.test.duckdns.org:9001",
    username: "local",
    password: "12345",
    clientId: "frontend",
    rejectUnauthorized: false,
  };
    
  @NgModule({
    imports: [
      CommonModule,
      MqttModule.forRoot(MQTT_SERVICE_OPTIONS)
    ]

WebSocket connection to 'wss://mqtt-ssl.test.duckdns.org:9001/' failed:

Is there any additional step required?

I open the frontend via: https://frontend.test.duckdns.org (chrome) and starting it with run config: "ng serve --host 192.168.2.178 --disable-host-check"

I also use MQTTX and I can connect with the same config as I use in the frontend.

1 Answer 1

2

Is the angular app loaded with https using the same self signed cert? No browser will prompt to accept a untrusted certificate if it's first accessed via Javascript.

You will either need to import the certificate into the browsers trust store (how to do that differs by browser type) or load the page/application using the same certificate and accept the warning before the Javascript MQTT client tries to connect.

Browsers can also not honour rejectUnauthorized: false

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, after i added the certificate it worked!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.