Modify frontend to run from an arbitrary subdirectory #171
Labels
enhancement
Request for a change to existing functionality
high-priority
Needs immediate extra focus
Projects
The frontend currently expects to be served by the top level domain. If this domain were
https://justincampbell.dev/
, the frontend assumed its relative path is/
. However, in order to support a reverse proxy in production as described in this comment, the frontend will need to be able to be served from a subdomain.Ideally this configuration would come from a single point of configuration that is referenced throughout the project. This article points out several different methods of achieving this but is somewhat out of date. Using it as a starting point, the frontend needs to be modified in the following ways:
1: Add a
homepage
entry to thepackage.json
file.This value can be referenced in code by the
process.env.PUBLIC_URL
variable. This can either for a full top level domain likehttps://justincampbell.dev
or a path relative to the root of the top level domain. For example, if the frontend were to be served fromhttps://justincampbell.dev/cats
, the path relative to the root of the top level domain would be/cats
.Example:
2: Update non-client side routing.
Currently only API calls via
fetch()
are not client side routed. After ahomepage
entry has been added in step one, allfetch()
requests to the API should be updated by using formatting strings and prepending the request path with theprocess.env.PUBLIC_URL
variable:3: Add a
basename
to React Router.For all client side routing, we can set a
basename
attribute that prepends all Route and Link component paths. By using thehomepage
value from above as thebasename
we can have fully relative Links and Routes like this:The text was updated successfully, but these errors were encountered: