Skip to content

Commit

Permalink
Add development option per url
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed Aug 21, 2023
1 parent a1a88ae commit b61e5db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deps.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { makeRpcCall } from "https://dev.zaubrik.com/schicksal@v0.0.7/client/dist/mod.js";
export { makeRpcCall } from "https://dev.zaubrik.com/schicksal@v0.0.8/client/dist/mod.js";
15 changes: 14 additions & 1 deletion shadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ export class Shadow extends HTMLElement {
this._waitingList.size === 0;
}

/**
* Shows if the client's location is the 'localhost'. Only one subdomain is
* allowed.
* @private
*/
_isDevelopment =
window.location.hostname.replace(/^[^.]+\./g, "") === "localhost";

/**
* Access the 'shadowRoot' through the property 'root'.
* @type {ShadowRoot}
Expand Down Expand Up @@ -283,7 +291,9 @@ export class Shadow extends HTMLElement {
* @returns {Promise<void>}
*/
async _makeRpcCallAndRender(method, property) {
const urlOrPath = this.getAttribute("rpc-url");
const urlOrPath = this.getAttribute("dev-url") && this._isDevelopment
? this.getAttribute("dev-url")
: this.getAttribute("rpc-url");
if (isString(urlOrPath)) {
const [url, jwt] = this._getUrlAndJwt(urlOrPath);
try {
Expand Down Expand Up @@ -368,6 +378,9 @@ export class Shadow extends HTMLElement {
(name === "json-url" || name === "html-url" || name === "init-url") &&
isString(newValue)
) {
if (this.getAttribute("dev-url") && this._isDevelopment) {
newValue = this.getAttribute("dev-url");
}
this._isPaused = true;
this._updateFromAttribute(name, newValue);
this._fetchAndUpdate(name, newValue)
Expand Down

0 comments on commit b61e5db

Please sign in to comment.