Skip to content

Commit

Permalink
Merge pull request #3628 from rstudio/joe/feature/autoreload-custom-url
Browse files Browse the repository at this point in the history
Add ability for autoreload ws to be at a custom URL
  • Loading branch information
jcheng5 authored May 4, 2022
2 parents 8eb7b05 + 59bddea commit 2cae041
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 14 deletions.
4 changes: 2 additions & 2 deletions inst/www/shared/shiny-autoreload.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions inst/www/shared/shiny-autoreload.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/shared/shiny-showcase.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions inst/www/shared/shiny-showcase.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/shared/shiny-testmode.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions inst/www/shared/shiny-testmode.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion srcts/build/extras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import babelPlugin from "esbuild-plugin-babel";

build({
bundle: true,
sourcemap: "inline",
sourcemap: true,
minify: true,
plugins: [babelPlugin()],
banner: banner,
Expand Down
17 changes: 8 additions & 9 deletions srcts/extras/shiny-autoreload.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable unicorn/filename-case */
let protocol = "ws:";
const protocol = (window.location.protocol === "https:") ? "wss:" : "ws:";
// Add trailing slash to path, if necessary, before appending "autoreload"
const defaultPath = window.location.pathname.replace(/\/?$/, "/") + "autoreload/";
const defaultUrl = `${protocol}//${window.location.host}${defaultPath}`;

if (window.location.protocol === "https:") protocol = "wss:";

let defaultPath = window.location.pathname;

if (!/\/$/.test(defaultPath)) defaultPath += "/";
defaultPath += "autoreload/";

const ws = new WebSocket(protocol + "//" + window.location.host + defaultPath);
// By default, use the defaultUrl. But if there's a data-ws-url attribute on our
// <script> tag, use that instead.
const wsUrl = document.currentScript.dataset.wsUrl || defaultUrl;
const ws = new WebSocket(wsUrl);

ws.onmessage = function (event) {
if (event.data === "autoreload") {
Expand Down

0 comments on commit 2cae041

Please sign in to comment.