Skip to content

Commit

Permalink
add support for loading script resources prefixed by create-react-app…
Browse files Browse the repository at this point in the history
… PUBLIC_URL env
  • Loading branch information
oHaiyang committed Apr 19, 2018
1 parent 994faae commit 7a7d0a1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/snapshot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* Wraps a jsdom call and returns the full page */

import jsdom from 'jsdom'
import urlLib from 'url'

const publicUrl = process.env.PUBLIC_URL
const publicUrlHost = publicUrl && urlLib.parse(publicUrl).host;

export default (protocol, host, path, delay) => {
return new Promise((resolve, reject) => {
Expand All @@ -12,6 +16,10 @@ export default (protocol, host, path, delay) => {
resourceLoader(resource, callback) {
if (resource.url.host === host) {
resource.defaultFetch(callback);
} else if (publicUrl && resource.url.host === publicUrlHost) {
const mappedLocaleResourceUrl = resource.url.format().replace(publicUrl, `${protocol}//${host}`);
resource.url = urlLib.parse(mappedLocaleResourceUrl);
resource.defaultFetch(callback);
} else {
callback()
}
Expand Down

0 comments on commit 7a7d0a1

Please sign in to comment.