From 177677c19245d63598506ef212bd999d7a13dbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 8 Jun 2020 00:53:41 +0200 Subject: [PATCH] feat: add support for the Authorization header in the UI --- public/app.js | 21 ++++++++++++--------- public/index.html | 10 ++++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/public/app.js b/public/app.js index f97ba807..98d8dd25 100644 --- a/public/app.js +++ b/public/app.js @@ -79,13 +79,13 @@ foo`; if (hubUrl) settingsForm.hubUrl.value = new URL(hubUrl, topic.value); const subscribeTopics = subscribeForm.topics; - if (!subscribeTopics.value) subscribeTopics.value = topic.value; + if (subscribeTopics.value === "https://example.com/my-private-topic") + subscribeTopics.value = topic.value; // Set publish default values const publishTopics = publishForm.topics; - if (!publishTopics.value) { + if (publishTopics.value === "https://example.com/my-private-topic") publishTopics.value = topic.value; - } return response.text(); }) @@ -99,11 +99,6 @@ foo`; subscribeForm.onsubmit = function (e) { e.preventDefault(); - if (settingsForm.authorization.value === "header") { - alert("EventSource do not support setting HTTP headers."); - return; - } - eventSource && eventSource.close(); updates.innerText = "No updates pushed yet."; @@ -118,7 +113,15 @@ foo`; u.searchParams.append("Last-Event-ID", lastEventId.value); let ol = null; - eventSource = new EventSource(u); + if (settingsForm.authorization.value === "header") { + eventSource = new EventSourcePolyfill(u, { + headers: { + Authorization: `Bearer ${settingsForm.jwt.value}`, + }, + }); + } else { + eventSource = new EventSource(u); + } eventSource.onmessage = function (e) { if (!ol) { ol = document.createElement("ol"); diff --git a/public/index.html b/public/index.html index dca152dc..8cbbccdd 100644 --- a/public/index.html +++ b/public/index.html @@ -43,11 +43,11 @@

Settings

@@ -119,7 +119,7 @@

Subscribe

- +
@@ -162,7 +162,7 @@

Publish

- +

@@ -211,6 +211,8 @@

Publish

+ +