How do I use the middleware on a path other than '/' ?
See original GitHub issue❔ Question
How can I tell the Bundler middleware to serve out of a subdirectory path?
I’d like to serve a Parcel-bundled app as a subdirectory of an Express app. For production I plan on just pointing Nginx to the dist/
folder, but for development I’d like to integrate the Parcel middleware into the main server, with hot-reloading etc. I’ve therefore followed the API docs and attached a new Bundler().middleware()
to the existing Express app
, and told the Bundler
what its public URL is:
app.use('/app/', new Bundler(__dirname+'/../browserclient/src/index.html', {
publicUrl: '/app/',
}).middleware())
Unfortunately, this just serves the index page for everything under /app/, including the JS and CSS bundles. This appears to be because of https://github.com/parcel-bundler/parcel/blob/0b98eedf2d9cb1a5232329d0d41e36bdef2b87bd/packages/core/parcel-bundler/src/Server.js#L57-L63 which checks if the middleware is serving a known path under options.publicURL
. Unfortunately since I’m using app.use(path, ...)
the pathname
variable is relative to /app/ (that is, it goes /index.deadbeef.js
, not /app/index.deadbeef.js
) and so never matches, and the bundled code can never be served. If I just tell it to app.use(new Bundler())
then it works, but Parcel also takes over the rest of the server and starts handing out its index instead of 404 pages.
🌍 Your Environment
Software | Version(s) |
---|---|
Parcel | 1.12.3 |
Node | 8.9.4 |
Express | 4.13.4 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
But this is confusing. It is better if Parcel use
req.originalUrl
if it is defined, instead of using req.url, with which Parcel cannot detect the middleware is used for root (/) path or another url.This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.