New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hosting react site on node.js and redirect all pages to index.html #4997

Closed
Leejjon opened this Issue Sep 11, 2018 · 1 comment

Comments

Projects
None yet
1 participant
@Leejjon

Leejjon commented Sep 11, 2018

Hi, I'm trying to build a single page progressive web app with full clientside routing. This seemed to work out of the box.

I am hosting my react.js app with node.js on google app engine, and configured it like instructed at:
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#other-solutions
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#other-solutions

My site:
https://nodejs-static.appspot.com/

The static files such as js and css are perfectly reachable:
https://nodejs-static.appspot.com/static/css/main.c17080f1.css

As you can see everything loads fine. But if you go into a sub path like:
https://nodejs-static.appspot.com/haha/haha

It will still load the index page (good right?) but whenever it tries to load the js and css files, it will just return the index.html instead of css/js.
https://nodejs-static.appspot.com/haha/static/css/main.c17080f1.css

How do you guys usually prevent this from happening so that it loads the correct js/css on sub paths?

It would be easiest if the create-react-app would give an option for my index.html to just load the css/js/favicon/manifest.json directly from the root of my site regardless on which path it would be (eg: nodejs-static.appspot.com/first or nodejs-static.appspot.com/first/second or nodejs-static.appspot.com/first/second/third)

I have multiple domain names for the site I want to build (for multiple languages) so I wouldn't want to hardcode it.

@Leejjon

This comment has been minimized.

Show comment
Hide comment
@Leejjon

Leejjon Sep 12, 2018

I found out that simply removing the homepage attribute in my package.json would make the scripts appear like:

<script type="text/javascript" src="/static/js/main.8c8eed99.js"></script>

Which makes it always load the JS and CSS from the root.

Leejjon commented Sep 12, 2018

I found out that simply removing the homepage attribute in my package.json would make the scripts appear like:

<script type="text/javascript" src="/static/js/main.8c8eed99.js"></script>

Which makes it always load the JS and CSS from the root.

@Leejjon Leejjon closed this Sep 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment