Skip to content

Commit

Permalink
Merge pull request #120 from Shopify/issues/5179/live-reload-safari
Browse files Browse the repository at this point in the history
Fix webSocket for liveReload in Safari
  • Loading branch information
henrytao-me authored May 31, 2021
2 parents fcbaebd + 3f6f309 commit 9eddefa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/argo-run/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ export async function dev(...args: string[]) {
const publicUrl = namedArgument('publicUrl', args);
const tunnelStarted = Boolean(publicUrl);
const filename = 'extension.js';
const scriptUrl = new URL(
`${PUBLIC_PATH}${filename}`,
publicUrl || url,
).toString();
const scriptUrl = new URL(`${PUBLIC_PATH}${filename}`, publicUrl || url);
const isHttps = scriptUrl.protocol === 'https:';

const compiler = webpack(
createWebpackConfiguration({
Expand All @@ -42,8 +40,12 @@ export async function dev(...args: string[]) {
publicPath: PUBLIC_PATH,
},
hotOptions: {
https: false,
webSocket: {host: 'localhost', port, path: WEBSOCKET_PATH},
https: isHttps,
webSocket: {
host: scriptUrl.hostname,
port: Number(scriptUrl.port) || (isHttps ? 443 : 80),
path: WEBSOCKET_PATH,
},
},
}),
);
Expand Down Expand Up @@ -205,7 +207,7 @@ export async function dev(...args: string[]) {
// https://github.com/Shopify/post-purchase-devtools/blob/master/src/background/background.ts#L16-L35
app.get(LEGACY_POST_PURCHASE_DATA_PATH, (_, res) => {
res.set('Access-Control-Allow-Origin', '*');
res.json(getLegacyPostPurchaseData(scriptUrl, extension));
res.json(getLegacyPostPurchaseData(scriptUrl.toString(), extension));
});
},

Expand Down Expand Up @@ -251,7 +253,7 @@ export async function dev(...args: string[]) {
if (isPostPurchaseExtension) {
log(
`You can append this query string: ${convertLegacyPostPurchaseDataToQueryString(
getLegacyPostPurchaseData(scriptUrl, extension),
getLegacyPostPurchaseData(scriptUrl.toString(), extension),
)}`,
);
} else if (tunnelStarted) {
Expand Down

0 comments on commit 9eddefa

Please sign in to comment.