-
SummaryAs referenced in a lot of issues (but I don't think documented), Client only paths work well in development and even while using gatsby-serve, but not when accessed directly when served from express. I am serving 'public' to an express server hosted on an ec2. I want to avoid configuring a URL rewrite or redirect through the provider, and want to contain the solution entirely within the node app repo if I can (docker and nginx are on the table but I would like to avoid that too). Architecture: pages/ Configuring gatsby-node.js to allow for client only paths off /messages/, i.e: example.com/messages/1 :
as well as using react router on pages/index.html:
Any solutions? Environment (if relevant)System: |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Please do keep in mind that we generally don't recommend using either |
Beta Was this translation helpful? Give feedback.
-
@pieh thanks for the response! So I'm confused, I should copy what exactly? |
Beta Was this translation helpful? Give feedback.
-
gatsby/packages/gatsby/src/commands/serve.ts Lines 110 to 111 in 1cf0c27 readMatchPaths , matchPathRouter functions aswell
|
Beta Was this translation helpful? Give feedback.
-
Oh perfect! cool! I see what you were having me do - basically follow how gatsby serve works. Thanks! |
Beta Was this translation helpful? Give feedback.
-
What's the 'program' in the serve props and being passed to readMatchPaths? I can't find where that is being passed and how to recreate the object |
Beta Was this translation helpful? Give feedback.
gatsby serve
is alsoexpress
"app": https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/commands/serve.ts so if you do want to useexpress
, but you need it to do more thangatsby serve
, you could copy the client only paths "router" from that file to your own application.Please do keep in mind that we generally don't recommend using either
gatsby serve
or custom express app to host production gatsby sites, because CDNs mostly take away a lot of hairy problems you might need to solve on your own when running your own server (stuff like redundancy, maybe load balancing, etc), but I also acknowledge that it might not be "that simple" in various cases. Also keep in mind thatga…