Make client API calls relative instead of hardcoded localhost:5144
Some checks failed
CI/CD / build-test-deploy (push) Has been cancelled
Some checks failed
CI/CD / build-test-deploy (push) Has been cancelled
The client always called a hardcoded http://localhost:5144, which only worked when browser and server shared the same "localhost" — breaks for any real remote deployment, since the browser would try to reach that port on the visitor's own machine instead of the actual server. Now every environment routes /api/* to the server under the same origin the page was loaded from, so the client code needs no per-environment URL: - Docker (client container's own nginx) proxies /api/ to the server container. - `npm run dev` (Vite) proxies /api to localhost:5144 via server.proxy. - Production nginx (reverse proxy + TLS) just needs to forward everything to the client container, which already knows how to route /api itself. Also incidentally removes CORS from the picture everywhere, since none of these setups make a cross-origin request anymore.
This commit is contained in:
@@ -4,5 +4,11 @@ export default defineConfig({
|
||||
root: "src/Client",
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://localhost:5144",
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user