Concept of Base URL
(Related to icat-plus#235)
The idea is to use a base URL (sometimes called basename) to get rid of the necessity to potentially create a subdomain to host the icat-plus and datahub.
By default react apps already do have such a feature. By setting the environment variable PUBLIC_URL
you can define the base URL (see index.html). For example, setting PUBLIC_URL=/hello_world
will make the react app available at http://mywebapp.com/hello_world
. By setting the basename
attribute of the BrowserRouter
component, the concept is also available to the react router object. The implementation could look similar to this:
/* in src/App.js*/
. . .
import { Route, Switch, Redirect, useLocation, BrowserRouter } from 'react-router-dom';
. . .
function App() {
. . .
if (!user.sessionId) {
return (
<BrowserRouter basename={process.env.PUBLIC_URL}>
<Switch>
<Route path="/login">
. . .
In the example above, the login page would now be available at http://mywebapp.com/<PUBLIC_URL>/login
A reverse proxy would be able to reroute frontend calls based on the defined PUBLIC_URL
environment variable, without the necessity of a subdomain.