Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(react-scripts): allow PUBLIC_URL in develoment mode#7259

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
andriijas merged 1 commit intofacebook:masterfromunrevised6419:public-url-in-development
Feb 2, 2020
Merged

feat(react-scripts): allow PUBLIC_URL in develoment mode#7259

andriijas merged 1 commit intofacebook:masterfromunrevised6419:public-url-in-development
Feb 2, 2020

Conversation

@unrevised6419
Copy link

@unrevised6419unrevised6419 commentedJun 21, 2019
edited
Loading

AllowPUBLIC_URL in development mode

Public API

Private API

  • Combinedpaths.publicUrl andpaths.servedPath intopaths.publicUrlOrPath
  • Extracted all logic intoreact-dev-utils/getPublicUrlOrPath (no side effects)
  • MovedevalSourceMapMiddleware anderrorOverlayMiddleware first in the middleware chain, redirect does not affect them.
  • Moved proxy middleware after redirect (this is the case what most want, proxy should respectPUBLIC_URL
  • AdaptednoopServiceWorkerMiddleware to serve fromservedPath
  • Updatedwebpack-dev-server@3.9.0 towebpack-dev-server@3.10.0

Blocked bywebpack/webpack-dev-server/pull/2150
Blocked bywebpack/webpack-dev-server/pull/2374
Blocked byhttps://github.com/webpack/webpack-dev-server new patch release

Closes#6280
Closes#6135
Closes#4158

tim-phillips, Flydiverny, Silic0nS0ldier, jrpedrianes, schemburkar, marcuslindfeldt, gergely-nagy, silverwind, sepehrthirdbridge, sepehrs, and 31 more reacted with thumbs up emojiulrichb, vnctaing, and PavelPolyakov reacted with heart emoji
@unrevised6419unrevised6419 changed the title<!-- Thank you for sending the PR!feat(react-scripts): allow PUBLIC_URL in develoment modeJun 21, 2019
Copy link

@ArnaudBarreArnaudBarre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

packages/react-scripts/config/webpack.config.js L. 561-563 to update

unrevised6419 reacted with thumbs up emoji
@unrevised6419
Copy link
Author

@ArnaudBarre done!

ArnaudBarre reacted with thumbs up emoji

Copy link
Contributor

@mrmckebmrmckeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@iansu or@ianschmitz - can I get your thoughts on this one?

@mrmckebmrmckeb self-assigned thisJun 26, 2019
Copy link

@jtblanchejtblanche left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this fixes the issue I mentioned at#6280 (comment) 👍

@64BitAsura
Copy link

64BitAsura commentedJul 13, 2019
edited
Loading

@iansu@Timer@gaearon@amyrlam@ianschmitz@petetnt@bugzpodder please review this PR, if all good merge it ASAP and make release please 🙏 , my projects requires and also I don't want to eject since we don't have enough resource to setup packer env 😢

unrevised6419, lucasmogari, mdapper, carolsoaressantos, ClaudioFuriniJr, andercampanha, andrerfarias, AZanellato, phsacramento, RafaelCamarda, and 8 more reacted with thumbs up emoji

@mrmckeb
Copy link
Contributor

@sambathl I'm chasing a second review on this, and then we can merge it in.

gergely-nagy, mdapper, tim-phillips, 64BitAsura, and areq reacted with hooray emoji

@heyimalex
Copy link
Contributor

I don't think it works when"homepage": ".".

@heyimalex
Copy link
Contributor

Ithink all that needs to change is webpackDevServer.config.js needs to check for the relative path when setting publicPath.

publicPath:paths.servedPath==="./" ?"/" :paths.servedPath.slice(0,-1)
unrevised6419 reacted with thumbs up emoji

@unrevised6419
Copy link
Author

unrevised6419 commentedJul 15, 2019
edited
Loading

There is also a problem when setting homepage/something and opening/,
manifest.json and favicon.ico return 404 trying to loadhttp://localhost:3000/%PUBLIC_URL%/manifest.json andhttp://localhost:3000/%PUBLIC_URL%/favicon.ico

Edit: In this case dev server just served clearindex.html content without injecting dynamic vars

@heyimalex
Copy link
Contributor

@iamandrewluca Hm, I'm actually not getting that anymore with my changes, so maybe the PUBLIC_URL thing was fixed by ad7e29b? But the dev server is definitely serving index.html when requests forfavicon.ico are made if homepage is set.

@raix
Copy link
Contributor

@iamandrewluca not sure if merging in master will fix the build issue / or at least rerun the build?

@unrevised6419
Copy link
Author

unrevised6419 commentedJan 13, 2020
edited
Loading

@raix made a rebase to trigger the build. It seems there is a babel plugin dependency error comming from master.

raix, djbeadle, and vnctaing reacted with confused emoji

@lucasmogari
Copy link

I'm trying this branch. I'm curious about why the public url have to end with a slash?

If I set the public_url with for example: "PUBLIC_URL=/test" and browsehttp://localhost:3000/test, it redirects the url to:http://localhost:3000/test/test

Btw, thanks for this PR, it's very useful.

@unrevised6419
Copy link
Author

unrevised6419 commentedJan 14, 2020
edited
Loading

If I set the public_url with for example: "PUBLIC_URL=/test" and browsehttp://localhost:3000/test, it redirects the url to:http://localhost:3000/test/test

It should not, I'll check.

@lucasmogari
Copy link

Another thing I noticed is that when reloadinghttp://localhost:3000/test/some-path, it returns a 404 error. Reloadinghttp://localhost:3000 works.

I don't know if it's related, but I'm running the apps behind a reverse proxy (nginx).

listen 3000;# App with PUBLIC_URL=/testlocation /test {    proxy_pass http://localhost:3020;    proxy_set_header Host $host;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location / {    proxy_pass http://localhost:3010;    proxy_set_header Host $host;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}

@unrevised6419
Copy link
Author

@lucasmogari onhttp://localhost:3000 is your nginx proxy?

@raix
Copy link
Contributor

@lucasmogari shouldn't it be:

location /test {    proxy_pass http://localhost:3020/test;
unrevised6419 reacted with thumbs up emoji

@lucasmogari
Copy link

It actually works both ways. According to nginx docs:

https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

If the address is specified without a URI, or it is not possible to determine the part of URI to be replaced, the full request URI is passed

The refresh problem happens in both ways too. I think there's something related to what is described in the docs, but there's no guide for nginx.

https://create-react-app.dev/docs/deployment/#serving-apps-with-client-side-routing

raix reacted with thumbs up emoji

@lucasmogari
Copy link

lucasmogari commentedJan 15, 2020
edited
Loading

@lucasmogari onhttp://localhost:3000 is your nginx proxy?

Yes. What I'm trying to do:

http://localhost:3000 proxies tohttp://localhost:3010/ (main app)
http://localhost:3000/test proxies tohttp://localhost:3020/test (test app)

In dev, refreshinghttp://localhost:3000/some-path works, buthttp://localhost:3000/test/some-path returns 404.

@lucasmogari
Copy link

I found that adding the option (index: paths.publicUrlOrPath) to webpackDevServer.config.js fixed the problem with refreshing:

historyApiFallback: {      // Paths with dots should still use the history fallback.      // See https://github.com/facebook/create-react-app/issues/387.      disableDotRule: true,      index: paths.publicUrlOrPath,},

@raix
Copy link
Contributor

Just a kind reminder - in 5 days / the 26th of January the original pr for this pull-request turns 1 year. Not often pull-requests live this long so I'm not sure if I should bring cake or flowers? :)

(Disclaimer: I'm not trying to push or rush things - even if we desperately want this to be merged)

nicholaai and nimiak reacted with confused emojiFlydiverny, keeslampe, and djbeadle reacted with heart emoji

@unrevised6419
Copy link
Author

@raix 😄 will live till will be merged 🌹 🌷 💮

SergeyVolynkin, bodinsamuel, djbeadle, and sdobz reacted with thumbs up emojiFlydiverny, raix, djbeadle, vnctaing, and bodinsamuel reacted with heart emoji

@andriijas
Copy link
Contributor

@iamandrewluca Can you rebase locally and push?

unrevised6419 reacted with thumbs up emoji

@unrevised6419
Copy link
Author

unrevised6419 commentedJan 31, 2020
edited
Loading

@lucasmogari I addressed the issues you encoutnered, can you try again with the proxy?

/test now will not redirect to/test/
/test/some-path returns 200

@andriijas done!

@unrevised6419
Copy link
Author

unrevised6419 commentedJan 31, 2020
edited
Loading

PR Blocked by awebpack-dev-server patch release
webpack/webpack-dev-server/pull/2374

@andriijas
Copy link
Contributor

@iamandrewluca In case we forget, ping whenwebpack-dev-server releases a new version! Thanks for your patience!

@unrevised6419
Copy link
Author

Ok, I'll ping. Contacted a webpack maintaner for an ETA.

@lucasmogari
Copy link

@lucasmogari I addressed the issues you encoutnered, can you try again with the proxy?

/test now will not redirect to/test/
/test/some-path returns 200

With PUBLIC_URL=/test
/test is redirecting (returns 302) to /test/test
/test/some-path (returns 200)

With PUBLIC_URL=/test/
/test/ (returns 200)

Maybe it's some configuration here. I'm sorry, but I don't have too much time to debug right now.

Thanks again!

@unrevised6419
Copy link
Author

unrevised6419 commentedJan 31, 2020
edited
Loading

@lucasmogari Try in incognito mode. Or clear all data forlocalhost:3000
For me when I tested also redirected to/test/.
If previous was any 301 redirect fromlocalhost:3000/test tolocalhost:3000/test/, browser remembers that, and will always redirect.

If I openlocalhost:3000/test in incognito mode, it stays on this path.

Co-authored-by: Eric Clemmons <eric@smarterspam.com>Co-authored-by: Alex Guerra <alex@heyimalex.com>Co-authored-by: Kelly <kelly.milligan@gmail.com>
@unrevised6419
Copy link
Author

@andriijas all done! Need review.

raix, andriijas, mchelen, williamscs, nvioli, and tim-phillips reacted with hooray emojiFlydiverny, raix, mchelen, and tim-phillips reacted with heart emojiraix, andriijas, mchelen, williamscs, nvioli, and tim-phillips reacted with rocket emoji

@andriijasandriijas merged commit1cbc6f7 intofacebook:masterFeb 2, 2020
@andriijas
Copy link
Contributor

Thanks for your patience everyone, specially @iamandrewluca

If anyone wants to do additional testing on their projects - please do!

unrevised6419, schemburkar, mchelen, williamscs, nvioli, raix, djbeadle, and alexnagelberg reacted with hooray emoji

@kelly-tock
Copy link

Well done!

@unrevised6419unrevised6419 deleted the public-url-in-development branchFebruary 2, 2020 21:29
@unrevised6419
Copy link
Author

unrevised6419 commentedFeb 2, 2020
edited
Loading

I encountered some problems when using proxy with this feature. Investigating. Think I should reorder in a right way proxy middlewares.

Also one case
Having/test homepage, any fetch ex:/api/resource will redirect to/test/api/resource which I think is wrong.

Do we revert the PR, and create a new one with fixed problems, or we fix the problem till the next release?

@unrevised6419
Copy link
Author

unrevised6419 commentedFeb 3, 2020
edited
Loading

Found the issue. Will make a PR soon. Internal proxy that decides to proxy or not, does not know about public path

gergely-nagy, lucasmogari, raix, tim-phillips, and djbeadle reacted with thumbs up emoji

@locklockbot locked and limited conversation to collaboratorsFeb 9, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@amyrlamamyrlamAwaiting requested review from amyrlam

@bugzpodderbugzpodderAwaiting requested review from bugzpodder

@gaearongaearonAwaiting requested review from gaearon

@ianschmitzianschmitzAwaiting requested review from ianschmitz

@iansuiansuAwaiting requested review from iansu

@petetntpetetntAwaiting requested review from petetnt

@TimerTimerAwaiting requested review from Timer

12 more reviewers

@ArnaudBarreArnaudBarreArnaudBarre left review comments

@rvillalba-novettarvillalba-novettarvillalba-novetta left review comments

@andriijasandriijasandriijas approved these changes

@ecamalionteecamalionteecamalionte approved these changes

@phsacramentophsacramentophsacramento approved these changes

@ralftingralftingralfting approved these changes

@mrmckebmrmckebmrmckeb approved these changes

@mdappermdappermdapper approved these changes

@64BitAsura64BitAsura64BitAsura approved these changes

@RafaelCamardaRafaelCamardaRafaelCamarda approved these changes

@thiamsantosthiamsantosthiamsantos approved these changes

@jtblanchejtblanchejtblanche approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

@mrmckebmrmckeb

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

support PUBLIC_URL during development as well

22 participants

@unrevised6419@64BitAsura@mrmckeb@heyimalex@raix@andriijas@genesiscz@lucasmogari@kelly-tock@ecamalionte@phsacramento@ralfting@mdapper@RafaelCamarda@thiamsantos@ArnaudBarre@jtblanche@rvillalba-novetta@iansu@ianschmitz@facebook-github-bot@bugzpodder

[8]ページ先頭

©2009-2025 Movatter.jp