react-live + Gatsby + koa-static-server does not work when changing the root path served
FancyVase opened this issue · 2 comments
Hi, I have a Koa app that serves the built Gatsby app that has a react-live snippet. However, when setting the rootPath
property (to prefix the route for accessing my application), react-live
stops working.
I'm not too sure if this is an issue with react-live
, Gatsby
, Koa
, or a mix of all three. Everything else Gatsby-wise works fine, and I'm a bit stumped so I'm reaching out here first.
I've made a dummy Gatsby app to reproduce this:
https://github.com/FancyVase/react-live-build-error/
Any help appreciated!
I just checked and I can replicate this issue with a simple server:
python -m SimpleHTTPServer
When navigating to localhost:8000/public
, react-live
doesn't work.
However, navigating to public/
and then starting up the python server seems to work fine:
cd public/
python -m SimpleHTTPServer
Found the fix, non-issue for react-live
!
In case anyone runs into this issue, you need to tell Gatsby what the path prefix is so that it points to the right static assets:
https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/
Refer to the linked PR for exact fix, but the implementation for my repo was just to add the following:
// gatsby-config.js
+ pathPrefix: '/my-app',
// package.json
+ "build": "gatsby build --prefix-paths
+ "serve": "gatsby serve --prefix-paths
Shoutouts to @TrevorBurnham for the find.