I want to serve my React app from a different route, so that I can keep all of my servers on the same container group.
My Caddyfile looks like this:
fqdn {
handle_path /backend* {
reverse_proxy http://localhost:8000
}
handle_path /react-app* {
reverse_proxy http://localhost:3001 {
header_up Host {host}
header_up X-Forwarded-Host {host}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
}
}
handle {
reverse_proxy http://localhost:3000
}
# This will handle all other requests and route them to port 5000
handle {
reverse_proxy http://localhost:5000
}
}
It is clear that my backend server, and my two frontend servers are hosted on 8000, 3000, and 3001 respectively. Everything else works perfectly. If I host the react app on another container group, it works fine, as the route is then "/".
Here's my vite config:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
server: {
host: true,
port: 3001,
strictPort: true,
},
base: '/react-app/',
preview: {
port: 3001,
}
})
And my main.jsx for reference to routing:
ReactDOM.createRoot(document.getElementById('root')).render(
<Router basename="/">
<Routes>
<Route path="/" element={<Login />} />
<Route path="/app" element={<App />} />
</Routes>
</Router>
)
The issue I am facing is that since both the vite config, and caddyfile are pointing towards /react-app, I get infinite redirects, if I change the basename prop in the Router component. If I remove it, like in the above code, vite still searches for resources at the base path, so nothing gets loaded then also. For example, the below files do not get loaded as vite looks for them in fqdn/src/, instead of fqdn/react-app/src.
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import Login from './Login.jsx';
I serve the react app using npm run dev, which while amateurish is working fine for me so far. This is done using the dockerfile.
I would appreciate any insights on how to solve this frustrating issue. Thanks.








