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

Cannot serve built static assets from external CDN #936

Closed
EnoahNetzach opened this issue Oct 20, 2016 · 13 comments
Closed

Cannot serve built static assets from external CDN #936

EnoahNetzach opened this issue Oct 20, 2016 · 13 comments

Comments

@EnoahNetzach
Copy link
Contributor

EnoahNetzach commented Oct 20, 2016

Description

We have a SPA served from an AWS server (e.g. "https://s3.eu-central-1.amazonaws.com/...") but used on our domain (e.g. https://www.mydomain.com/...); we have some .svg files bundled within and our package.json "homepage" is set to the AWS url.

The .js and .css assets are retrieved correctly from AWS, but the browser tries to retrieve the .svg files from our domain, and of course it fails since they are hosted on the AWS server.

Expected behavior

Assets built in build/static/media/* are resolved from the domain specified in the package.json "homepage" value (i.e. "https://s3.eu-central-1.amazonaws.com/...").

Actual behavior

Static assets are resolved from the domain where the main.[hash].js is being loaded from (i.e. "https://www.mydomain.com/...").

Environment

  • npm ls react-scripts: [email protected]
  • node -v: v6.8.0
  • npm -v: 3.10.8
  • Operating system: any OS
  • Browser and version: any browser

Reproducible Demo

Basic CRA setup with external files imported.

@gaearon
Copy link
Contributor

gaearon commented Oct 20, 2016

I’d take a PR that implements this via reading PUBLIC_URL env variable. Please see #694 (comment).

@EnoahNetzach
Copy link
Contributor Author

That's perfect, so PUBLIC_URL=https://s3.eu-central-1.amazonaws.com/... npm run build would work as we expect, right?

btw: thank y'all for your work, time & dedication!

@mars
Copy link
Contributor

mars commented Oct 22, 2016

How about namespacing this as REACT_APP_PUBLIC_URL so that it's automatically white listed into process.env along with other custom environment vars?

@EnoahNetzach
Copy link
Contributor Author

@mars would work for me, @gaearon, any downsides?

@EnoahNetzach
Copy link
Contributor Author

Any news on this issue?

@gaearon
Copy link
Contributor

gaearon commented Oct 28, 2016

How about namespacing this as REACT_APP_PUBLIC_URL so that it's automatically white listed into process.env along with other custom environment vars?

It is already available as process.env.PUBLIC_URL, as documented. I don't want to namespace it because it has a special meaning not defined by the user.

@sjmueller
Copy link

Is there a clear explanation of how this will work? Here's what I tried:

  1. cloned the @EnoahNetzach's fork: https://github.com/EnoahNetzach/create-react-app
  2. npm link the forked version of react-scripts
  3. npm linked into my app
  4. create dist with PUBLIC_URL=https://s3.us-east-1.amazonaws.com/ npm run build
  5. ran with pushstate-server build

Expected

All references to static media would be structured with absolute references (i.e. https://s3.us-east-1.amazonaws.com/static/media/icon-1234.png)

Actual

All links were still relative: /static/media/icon-1234.png

@EnoahNetzach
Copy link
Contributor Author

@sjmueller in my experience it won't work after a npm link, the build dir is created in the create-react-app repo.

The steps to follow to reproduce in your case are:

  • unlink react-scripts if still linked
  • install react-scripts from the folder (in my case it is something like "file:../create-react-app/packages/react-scripts/")
  • run the build with PUBLIC_URL env var

@EnoahNetzach
Copy link
Contributor Author

@gaearon if I could ask, why this issue is in the 0.9.0 milestone while the related PR is in the 0.8.0 one?

@gaearon
Copy link
Contributor

gaearon commented Dec 6, 2016

Sorry, both should be tagged as 0.9.0 now.
I remember about it and it won't skip another minor again.

@EnoahNetzach
Copy link
Contributor Author

@gaearon ahah sorry for the psychological terrorism!

@Timer Timer mentioned this issue Feb 8, 2017
@Timer
Copy link
Contributor

Timer commented Feb 10, 2017

Resolved in #937 and #1504.

@Timer
Copy link
Contributor

Timer commented Feb 11, 2017

Hi @EnoahNetzach! This is out in 0.9.0.

ruupert added a commit to UniversityOfHelsinkiCS/labtool that referenced this issue Feb 8, 2018
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants