saltyshiomix / react-ssr

React SSR as a view template engine
https://npm.im/@react-ssr/express
MIT License
267 stars 44 forks source link

feature-request - support for mounting as a sub application in express #18

Closed brendonjohn closed 4 years ago

brendonjohn commented 4 years ago

I'm wanting to use react-ssr as a sub app in a larger web application. Currently, there is an assumption that react-ssr is configure for the root path of a website.

What I am attempting to do:

const subApp = express()
const mainApp = express()

await registerSSR(subApp)
mainApp.use('/custom-app/', subApp)

mainApp.listen(3000, () => console.log('hello'))

From what I can tell, there are three issues to overcome for this to be possible:

  1. The HTML templates created in the stringify folder assume that the react-ssr resources does not need a prefix.
  2. The middleware proxy in development mode cannot be configured for incoming paths to have a prefix

Only the first item is required for running in production and this can be achieved by providing a redirect on the server. I made a gist as an example.

If I could provide custom options to http-proxy-middleware, this would let me have a development environment for my app. I would use the custom config to provide a pathRewrite option.

What do you think? I'll raise a PR so you can see.

saltyshiomix commented 4 years ago

If any updates, feel free to reopen the issue.