diff --git a/client/login.html b/client/login.html index 037e20a..b328eec 100644 --- a/client/login.html +++ b/client/login.html @@ -15,7 +15,7 @@ diff --git a/client/src/components/seats-widget.js b/client/src/components/seats-widget.js index 069d0ee..baacf93 100644 --- a/client/src/components/seats-widget.js +++ b/client/src/components/seats-widget.js @@ -1,4 +1,4 @@ -import { createRoomEventStream, Database, getLoggedUser } from '../index.js' +import { BASE_URL, createRoomEventStream, Database, getLoggedUser } from '../index.js' import { addTooltipElementListener, resetTooltip, setTooltipText } from './tooltip.js' async function renderWidget(elSeatMap, seats) { @@ -67,7 +67,7 @@ export async function createSeatWidget($roomGrid, roomId) { // Listener for takeing or leaving a seat $seat.addEventListener('click', async () => { if (!user) { - location.href = '/login.html' + location.href = `${BASE_URL}/` return } diff --git a/client/src/index.js b/client/src/index.js index 5212829..7850f75 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -1,24 +1,24 @@ import './style.scss' +export const BASE_URL = import.meta.env.BASE_URL.replace(/\/$/, '') + let USER = false export async function getLoggedUser() { if (USER === false) { console.log('Caching user data...') - USER = await (await fetch(`${import.meta.env.BASE_URL}api/user`)).json() + USER = await (await fetch(`${BASE_URL}/api/user`)).json() } return USER } export function createRoomEventStream(roomId) { - return new EventSource(`${import.meta.env.BASE_URL}api/room_events?id=${roomId}`) + return new EventSource(`${BASE_URL}/api/room_events?id=${roomId}`) } export const Database = { async getSeats(roomId) { - const seatList = await ( - await fetch(`${import.meta.env.BASE_URL}api/room/seats?id=${roomId}`) - ).json() + const seatList = await (await fetch(`${BASE_URL}/api/room/seats?id=${roomId}`)).json() const seats = {} seatList.forEach(seat => { @@ -28,7 +28,7 @@ export const Database = { return seats }, async occupySeat(seatId) { - const response = await fetch(`${import.meta.env.BASE_URL}api/seat/occupy?id=${seatId}`, { + const response = await fetch(`${BASE_URL}/api/seat/occupy?id=${seatId}`, { method: 'POST', }) @@ -39,7 +39,7 @@ export const Database = { await response.json() }, async leaveSeat(seatId) { - const response = await fetch(`${import.meta.env.BASE_URL}api/seat/leave?id=${seatId}`, { + const response = await fetch(`${BASE_URL}/api/seat/leave?id=${seatId}`, { method: 'POST', }) diff --git a/client/src/pages/index.js b/client/src/pages/index.js index dc34ac4..5e1a5d5 100644 --- a/client/src/pages/index.js +++ b/client/src/pages/index.js @@ -1,5 +1,5 @@ import { createGridLineCanvas } from '../components/gridlines.js' -import { getLoggedUser } from '../index.js' +import { BASE_URL, getLoggedUser } from '../index.js' import { createSeatWidget } from '../components/seats-widget.js' import { createClock } from '../components/clock.js' import { attachTooltip } from '../components/tooltip.js' @@ -15,8 +15,8 @@ const elLogoutButton = document.querySelector('#logout-button') const elRoomGrid = document.querySelector('.room-grid') async function logout() { - await fetch(`${import.meta.env.BASE_URL}api/logout`, { method: 'POST' }) - location.href = `${import.meta.env.BASE_URL}` + await fetch(`${BASE_URL}/api/logout`, { method: 'POST' }) + location.href = `${BASE_URL}` } async function main() { diff --git a/client/src/pages/login.js b/client/src/pages/login.js index 967a451..2c5265f 100644 --- a/client/src/pages/login.js +++ b/client/src/pages/login.js @@ -1,4 +1,4 @@ -import { getLoggedUser } from '../index.js' +import { BASE_URL, getLoggedUser } from '../index.js' // // Page Element @@ -33,7 +33,7 @@ function displayErrorString(e) { async function login() { try { - const response = await fetch(`${import.meta.env.BASE_URL}api/login`, { + const response = await fetch(`${BASE_URL}/api/login`, { method: 'POST', headers: { Accept: 'application/json, text/plain, */*', @@ -50,7 +50,7 @@ async function login() { return } - location.href = `${import.meta.env.BASE_URL}` + location.href = `${BASE_URL}/` } catch (e) { displayErrorString(e) } @@ -64,7 +64,7 @@ async function main() { const user = await getLoggedUser() console.log(user) if (user) { - location.href = `${import.meta.env.BASE_URL}` + location.href = `${BASE_URL}/` } elLoginButton.addEventListener('click', () => login())