How to use modern app with traccar-server backend IP

Everton 2 years 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 Tananaev 2 years 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.
Everton 2 years 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 Tananaev 2 years ago

You have to set up an external proxy.

Everton 2 years 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 Tananaev 2 years ago

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