Skip to content

Use relative path as fetch does in browser #2035

Closed

Description

@jim-king-2000

In browser, we could use relative path in fetch. For example:
fetch('/') // let support the complete url is https://www.abc.com

Shall we use the same pattern with mqtt.js?

client.connect('/mqtt') // Could the complete url be: wss://www.abc.com/mqtt?

Activity

  1. robertsLando commented on Jan 30, 2026

    @robertsLando
    Member

    Could the complete url be: wss://www.abc.com/mqtt?

    PR?

  2. jim-king-2000 commented on Jan 30, 2026

    @jim-king-2000
    Author

    It would take me a very long time to prepare a PR since the library is a little bit complicated. After my initial investigation, I find a clue. Since native WebSocket supports relative path, maybe we could think about using it to take place of ws.

  3. jim-king-2000 commented on Apr 3, 2026

    @jim-king-2000
    Author

    According to https://github.com/mqttjs/MQTT.js#customize-websockets-with-createwebsocket-websocket-only, we could use native WebSocket directly which supports relative path. The only thing left is to remove the url validation in the code base.

  4. robertsLando commented on Apr 7, 2026

    @robertsLando
    Member

    PR?

  5. added a commit that references this issue on May 20, 2026
    c4be563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions