How to use modern app with traccar-server backend IP

Everton2 months ago

Hello, great?

My backend has an IP and I use it in the browser to see the status. Ok, it's correct. However, I put this IP in vite.config.ts and ChangeServerPage.

At vite.config.ts
proxy: { "/api/socket": "ws://my-ip:443", "/api": "https://my-ip:443", },

At ChangeServerPage
const officialServers = [ "https://my-ip:443", "https://my-ip", "http://my-ip:8082", currentServer, ];

Do I need something more? I'm getting 404.

Anton Tananaev2 months ago

Your config definitely looks wrong:

  • ws://my-ip:443 - It seems like here you're using non-HTTPS WebSocket with HTTPS port.
  • https://my-ip:443 - Here you have HTTPS with an IP address, which is not possible.
Everton2 months ago

How to configure proxy to use my API URL?
I tryed to modify at vite.config and ChangeServerPage. But I get error because the aplication in PROD hit in my domain of the frontend.

Anton Tananaev2 months ago

You have to set up an external proxy.

Everton2 months ago

External proxy at vite.config?
I made this:

    server: {
      proxy: {
        "/api": {
          target: "https://api.mydomain.com.br",
          changeOrigin: true,
          secure: false,
          ws: true,
        },
      },

But my fetch("/api/server") at ServerProvider didn't get my api url. Have other file where I set API configuration?

Anton Tananaev2 months ago

Vite proxy is just for debugging. You need a proper proxy.