I’m trying to publish the frontend of my Redwoodjs application behind a proxy with Apache… Let’s say I have a single-page application with the following Routes.jsx
file:
import { Set, Router, Route } from '@redwoodjs/router'
import ScaffoldLayout from 'src/layouts/ScaffoldLayout'
const Routes = () => {
return (
<Router>
<Route path="/myapp" page={HomePage} name="home" />
<Route notfound page={NotFoundPage} />
</Router>
)
}
export default Routes
Basically, I’ve build my frontend with:
yarn rw build web
And then I served it with:
yarn rw serve web
After this it’ll serve my frontend on http://localhost:8910/myapp
, which works perfectly fine, the problem starts when I try to put this application behind a proxy like Apache using a basepath different /
(being in a different basepath is a requirement in my case)… Let’s say for example that I try to publish it on http://mypage.com/test/myapp
with the Apache configuration:
ServerName mypage.com
<Location "/test/">
ProxyPass http://localhost:8910/
ProxyPassReverse http://localhost:8910/
</Location>
Then I see the following errors on my page:
I know I can fix those errors with some rewrite rules as:
ServerName mypage.com
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/test/
RewriteRule ^/(.*)$ /test/$1 [R=301,L]
RewriteRule ^/favicon\.png$ /test/favicon.png [R=301,L]
<Location "/test/">
ProxyPass http://localhost:8910/
ProxyPassReverse http://localhost:8910/
</Location>
However, now my Redwoodjs application behind the reverse proxy doesn’t find the page for my application, and it doesn’t show any error as well:
It doesn’t make sense to me because the local address http://localhost:8910/myapp
works fine, so http://mypage.com/test/myapp
should work like that as well, shouldn’t it? The problem here is that even if I change the route of my application in the Routes.jsx
file, the command yarn rw serve web
will still serve some files on the path /
and that’s what’s causing the problem here I think.
Is there any way of completely changing the base path of the front end of my RedwoodJS application? Just so I can use it behind a reverse proxy like Apache without too many extra configurations?