Skip to content

Commit 9cab6e4

Browse files
committed
Ensure frontend urls are composed correctly
1 parent c67339e commit 9cab6e4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/core/config/config.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export const makeConfig = (env: EnvironmentService) =>
149149
.string('DEFAULT_TIMEZONE')
150150
.optional('America/Chicago');
151151

152-
frontendUrl = env.string('FRONTEND_URL').optional('http://localhost:3001');
152+
frontendUrl = env.url('FRONTEND_URL').optional('http://localhost:3001');
153153

154154
neo4j = (() => {
155155
const driverConfig: Neo4JDriverConfig = {};
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { createContext, type ReactElement, useContext } from 'react';
22
import { ServerException } from '~/common/exceptions';
33

4-
const FrontendUrlContext = createContext<string | undefined>(undefined);
4+
const FrontendUrlContext = createContext<Readonly<URL> | undefined>(undefined);
55

66
export const useFrontendUrl = (path: string) => {
77
const base = useContext(FrontendUrlContext);
88
if (!base) {
99
throw new ServerException('Frontend url has not been provided');
1010
}
11-
return base + path;
11+
path = path.startsWith('/') ? path.slice(1) : path;
12+
return new URL(path, base).toString();
1213
};
1314

14-
export const FrontendUrlWrapper = (url: string) => (el: ReactElement) =>
15+
export const FrontendUrlWrapper = (url: Readonly<URL>) => (el: ReactElement) =>
1516
<FrontendUrlContext.Provider value={url}>{el}</FrontendUrlContext.Provider>;

0 commit comments

Comments
 (0)