FIX: Only unregister service workers that belongs to Discourse.

This commit is contained in:
Guo Xiang Tan 2019-05-07 12:36:40 +08:00
parent 03169401ff
commit abbc639e0d
4 changed files with 16 additions and 10 deletions

View File

@ -82,7 +82,8 @@ export default Ember.Controller.extend({
actions: {
save() {
this.set("saved", false);
const url = extractDomainFromUrl(this.get("model.payload_url"));
const url = this.get("model.payload_url");
const domain = extractDomainFromUrl(url);
const model = this.get("model");
const isNew = model.get("isNew");
@ -103,10 +104,10 @@ export default Ember.Controller.extend({
};
if (
url === "localhost" ||
url.match(/192\.168\.\d+\.\d+/) ||
url.match(/127\.\d+\.\d+\.\d+/) ||
url === Discourse.BaseUrl
domain === "localhost" ||
domain.match(/192\.168\.\d+\.\d+/) ||
domain.match(/127\.\d+\.\d+\.\d+/) ||
url.startsWith(Discourse.BaseUrl)
) {
return bootbox.confirm(
I18n.t("admin.web_hooks.warn_local_payload_url"),

View File

@ -20,7 +20,7 @@ export default {
Discourse.ServiceWorkerURL
)
) {
registration.unregister();
this.unregister(registration);
}
}
});
@ -34,10 +34,16 @@ export default {
} else {
navigator.serviceWorker.getRegistrations().then(registrations => {
for (let registration of registrations) {
registration.unregister();
this.unregister(registration);
}
});
}
}
},
unregister(registration) {
if (registration.scope.startsWith(Discourse.BaseUrl)) {
registration.unregister();
}
}
};

View File

@ -443,11 +443,10 @@ module ApplicationHelper
def client_side_setup_data
service_worker_url = Rails.env.development? ? 'service-worker.js' : Rails.application.assets_manifest.assets['service-worker.js']
current_hostname_without_port = RailsMultisite::ConnectionManagement.current_hostname.sub(/:[\d]*$/, '')
setup_data = {
cdn: Rails.configuration.action_controller.asset_host,
base_url: current_hostname_without_port,
base_url: Discourse.base_url,
base_uri: Discourse::base_uri,
environment: Rails.env,
letter_avatar_version: LetterAvatar.version,

View File

@ -115,7 +115,7 @@ QUnit.testStart(function(ctx) {
// Allow our tests to change site settings and have them reset before the next test
Discourse.SiteSettings = dup(Discourse.SiteSettingsOriginal);
Discourse.BaseUri = "";
Discourse.BaseUrl = "localhost";
Discourse.BaseUrl = "http://localhost:3000";
Discourse.Session.resetCurrent();
Discourse.User.resetCurrent();
resetSite(Discourse.SiteSettings);