Skip to content
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

Fixed crawling of projects with publicPath != "/" #29

Merged
merged 1 commit into from
May 26, 2017

Conversation

kantenkugel
Copy link
Contributor

As connect-history-api-fallback would try to serve /200.html file for any non-found request, it would just fail and return a 404 page as pages generated with publicPath other than "/" would have the 200.html file within the publicPath subdirectory, not root. This commit wraps the historyApiFallback inside the publicPath route.

There is an additional optional step that I didn't implement here:
Switching the order of express.static() and the historyApiFallback.
Currently, it tries to serve the 200.html file first (if there is a GET request for text/html). Only after that fails (for non-html requests), files out of the static dir are served. This might be the wrong order as some static html-files (inside of the public folder) will never get served. Best would be to reorder those 2 to first serve existing static files, and only then fall back to the 200.html file

@kantenkugel
Copy link
Contributor Author

if requested i can swap the order of the 2 middlewares (as described above) and add the commit to this PR

@geelen
Copy link
Owner

geelen commented May 24, 2017

Yeah i've been having real trouble with the order of the loaders. This is where some proper tests would be super handy. I think this is good to merge, but let's leave the order of the loaders for now—I'll have a play with it soon and make sure it works on my two manual test projects

@kantenkugel
Copy link
Contributor Author

Ok I'll leave the PR as it is then

@kantenkugel
Copy link
Contributor Author

kantenkugel commented May 25, 2017

After thinking about it a little more:

You probably don't need to serve static html files anyway, as those are not from react and don't need to be snapshotted by react-snapshot. You only need external resources for your 200.html file (the built main.js file for example) and those are fine being served after the static 200.html for all html request.

Then again: if you have a link inside your react-driven app to a static html, react-snapshot will open the 200.html with the incorrect URL and will probably render some 404 site of your app which will replaces the static file in the output.

One option would be to re-enable the dot-rule for connect-history-api-fallback, as react normally doesn't generate *.html routes.
Only problem then is that the error message about render() not being called is printed out.

@geelen
Copy link
Owner

geelen commented May 26, 2017

Yeah I'm not sure if that's better. Potentially adding data-react-snapshot-nofollow attribute to links or adding paths to the exclude (you can use wildcard matches there too) is enough...

@geelen
Copy link
Owner

geelen commented May 26, 2017

Let's move that discussion elsewhere for now. I wanna merge & release this.

@geelen geelen merged commit 7c3d166 into geelen:master May 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants