Skip to content

Commit 683750d

Browse files
committed
add serviceUrl to client
1 parent c7490ef commit 683750d

3 files changed

Lines changed: 34 additions & 17 deletions

File tree

public/js/wol.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
export async function startWoLProcess({
22
endpoint = "/start",
33
onwsopen = () => {
4-
outputHandler("WebSocket connected.")
4+
outputHandler("WebSocket connected")
55
},
66
onwserror = (err) => {
7-
outputHandler("WebSocket connection failed.")
7+
outputHandler("WebSocket connection failed")
88
errorHandler(err)
99
},
1010
onwsclose = () => {
11-
outputHandler("WebSocket closed.")
11+
outputHandler("WebSocket closed")
1212
},
1313
onerror = (ws, msg) => {
14-
outputHandler("Failed to start service.")
14+
outputHandler("Failed to start service")
1515
ws.close()
1616
errorHandler(msg.message)
1717
},

src/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function Init() {
138138
locale: req.user.locale,
139139
email: req.user.email,
140140
},
141-
service: serviceUrl,
141+
serviceUrl: serviceUrl,
142142
})
143143
})
144144

views/home.ejs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
locale: "<%= user.locale %>",
4343
}
4444
45+
const serviceUrl = "<%= serviceUrl %>"
46+
const serviceURL = new URL(serviceUrl)
47+
4548
const userProfile = document.querySelector(".user .profile")
4649
4750
const output = document.getElementById("output")
@@ -54,16 +57,19 @@
5457
if (element) element.id = newId
5558
}
5659
57-
function handleError({
58-
host = "Server",
59-
msg = "Something went wrong",
60-
} = {}) {
60+
function handleError({ host = "Service", msg = "" } = {}) {
61+
msg = msg.trim()
62+
63+
if (msg === "") {
64+
msg = `${host} seems to be unreachable`
65+
}
66+
6167
setTimeout(() => {
6268
changeAnimation("spin", "cross-line")
6369
changeAnimation("hide", "add-line")
6470
65-
title.textContent = msg
66-
subtitle.textContent = `${host} seems to be unreachable`
71+
title.textContent = `Something went wrong`
72+
subtitle.textContent = msg
6773
}, 250)
6874
}
6975
@@ -87,18 +93,29 @@
8793
startWoLProcess({
8894
outputHandler: handleOutput,
8995
errorHandler: (msg) => {
90-
handleError()
96+
handleError({
97+
msg: msg,
98+
host: serviceURL.hostname,
99+
})
91100
},
92101
onwsopen: () => {
93102
handleSubtitle("Starting process...")
94103
handleOutput("WebSocket connected.")
95104
},
96105
onsuccess: (ws, msg) => {
97-
outputHandler("Service is online! Redirecting...")
98-
ws.close()
99-
setTimeout(() => {
100-
window.location.href = msg.url
101-
}, 250)
106+
if (msg.url !== serviceUrl) {
107+
handleOutput()
108+
ws.close()
109+
handleError({
110+
msg: "Service URL was modified",
111+
})
112+
} else {
113+
handleOutput("Service is online! Redirecting...")
114+
ws.close()
115+
setTimeout(() => {
116+
window.location.href = msg.url
117+
}, 250)
118+
}
102119
},
103120
})
104121
}

0 commit comments

Comments
 (0)