The frontend and backend can now be reverse proxied together

This commit is contained in:
Jarrett Gilliam
2022-07-22 14:45:50 -05:00
parent d4aac95fcd
commit 221cb86000
2 changed files with 10 additions and 1 deletions

View File

@@ -52,6 +52,7 @@ export default {
}),
replace({
BACKEND_PORT: JSON.stringify(process.env.BACKEND_PORT),
BACKEND_IS_PROXIED: JSON.stringify(!!process.env.BACKEND_IS_PROXIED),
preventAssignment: true
}),
// we'll extract any component CSS out into

View File

@@ -7,7 +7,15 @@ const message = writable('');
let socket;
function initSocket() {
socket = new WebSocket(`ws://${location.hostname}:${BACKEND_PORT}/wol/`);
if (BACKEND_IS_PROXIED) {
const socketUrl = new URL('/wol/', window.location.href);
socketUrl.protocol = socketUrl.protocol.replace('http', 'ws');
socket = new WebSocket(socketUrl);
}
else {
socket = new WebSocket(`ws://${location.hostname}:${BACKEND_PORT}/wol/`);
}
// Connection opened
socket.addEventListener('open', function () {