Add basic realtime communication (#2118)

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-06-18 18:40:28 +02:00 committed by GitHub
parent 3b86afc17c
commit 0da51bba67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 624 additions and 53 deletions

View file

@ -6,8 +6,25 @@
import { isMockMode } from './test-modes'
if (!isMockMode && process.env.NEXT_PUBLIC_BACKEND_BASE_URL === undefined) {
throw new Error('NEXT_PUBLIC_BACKEND_BASE_URL is unset and mock mode is disabled')
/**
* Generates the backend URL from the environment variable `NEXT_PUBLIC_BACKEND_BASE_URL` or the mock default if mock mode is activated.
*
* @throws Error if the environment variable is unset or doesn't end with "/"
* @return the backend url that should be used in the app
*/
const generateBackendUrl = (): string => {
if (!isMockMode) {
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_BASE_URL
if (backendUrl === undefined) {
throw new Error('NEXT_PUBLIC_BACKEND_BASE_URL is unset and mock mode is disabled')
} else if (!backendUrl.endsWith('/')) {
throw new Error("NEXT_PUBLIC_BACKEND_BASE_URL must end with an '/'")
} else {
return backendUrl
}
} else {
return '/'
}
}
export const backendUrl = isMockMode ? '/' : (process.env.NEXT_PUBLIC_BACKEND_BASE_URL as string)
export const backendUrl = generateBackendUrl()