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

Default --public-url should be / and 404 when it is set to / #932

Closed
mightyiam opened this issue Mar 2, 2018 · 3 comments
Closed

Default --public-url should be / and 404 when it is set to / #932

mightyiam opened this issue Mar 2, 2018 · 3 comments

Comments

@mightyiam
Copy link

This is a 🐛 bug report.

So, I'd like to shed some light on this issue here, where I seem to be doing a minimal modern web app file and URL structure and using parcel with its defaults (and also not with defaults) and the results seem to be buggy. Let me show you what I mean.

So, I have parcel-bundler v1.6.2.

src/index.html is just

<body><script src="index.js"></script></body>

src/index.js is just:

document.body.innerHTML = '<h1>pass</h1>'

Now I run the command npx parcel build src/index.html and the resulting dist/index.html is:

<body><script src="/dist/93a004a8b369dc9199ccd961ac405894.js"></script></body>

And the resulting file structure is:

dist:
93a004a8b369dc9199ccd961ac405894.js  93a004a8b369dc9199ccd961ac405894.map  index.html

So, the script element's src attribute's value is wrong. I expect it to be /93a004a8b369dc9199ccd961ac405894.js, instead.

Now, regarding the --public-url option, I'd like to say two things: One is that I consider the above use case the most sane/reasonable use case. So, the for this use case, the defaults should suffice. Second, that I wasn't able to solve this by specifying --public-url. For example, with --public-url /, the script's src attribute is as I would expect it, /93a004a8b369dc9199ccd961ac405894.js. But then, with the serve command something is broken. When I do npx parcel serve --public-url / src/index.html and request http://localhost:1234/, I get a 404. When I request http://localhost:1234/index.html it works.

So, my suggestion is that --public-url will be / by default.

Also, there seems to be a bug when --public-url is /, here: /~https://github.com/parcel-bundler/parcel/blob/v1.6.2/src/Server.js#L46. The following:
!req.url.startsWith(bundler.options.publicURL) resolves to false and the default HTML index is not sent. Instead it tries the static files and sends a 404.

In summary, the --public-url / seems like a bug. Yet, please also fix the default. Because I do not see a reason for /dist to be the default or for the default to be whatever the output directory is.

My deployment workflow is that the contents of dist are the deployed files. They are served by a static file server (with support for 200.html) at /. This seems to me like it should be considered the common (and most straightforward) use case and thus the defaults should be based on that. Specifically, --public-url should be / by default (instead of whatever the output directory is).

Here is example code: /~https://github.com/mightyiam/parcel-bug-repro/tree/ac41eafa397f948dbcea35e3600aa43b52b1fdef.

@DeMoorJasper
Copy link
Member

This is currently the default behaviour not a bug, related to #838 and #714

@mightyiam
Copy link
Author

And thank you for parcel, BTW. Love it.

@mightyiam
Copy link
Author

Please read this carefully and consider reopening.

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

No branches or pull requests

2 participants