DEV Community

Cover image for Configure the create-react-app public URL post-build with Node.js and express

Configure the create-react-app public URL post-build with Node.js and express

Laurin Quast on March 29, 2020

Cover Art by Joshua Welch For a project, I had the requirement of making the public URL of the application configurable via an environment variabl...
Collapse
 
kiliman profile image
Kiliman • Edited

Have you considered using relative URLs?

PUBLIC_URL=.

Results in URLs like "./favicon.ico"

Then you can deploy your app to any folder, like /app, or /some/arbitrary/folder

dev-to-uploads.s3.amazonaws.com/i/...

Collapse
 
n1ru4l profile image
Laurin Quast

Yeah, I have considered using relative URLs but I think absolute URLs are more "clean".

My main points are that they are a bit confusing and harder to reason about.

Also, it seems like it would not work that well with client-side routing. Without the PUBLIC_URL we cannot find out what part of the path is the base, but I might be wrong here!

Do you have an example of client-side routing with a relative URL?

Collapse
 
josef37 profile image
Josef Wittmann

This one is gold!
Thank you so much for this article, Laurin.

I wanted to create a React admin interface for a WordPress plugin and faced exactly the same issue. Works like a charm now <3