diff --git a/packages/app-client/src/modules/config/config.constants.ts b/packages/app-client/src/modules/config/config.constants.ts index ef72d18f..3a49787d 100644 --- a/packages/app-client/src/modules/config/config.constants.ts +++ b/packages/app-client/src/modules/config/config.constants.ts @@ -9,4 +9,5 @@ export const buildTimeConfig: Config = { defaultNoteTtlSeconds: Number(import.meta.env.VITE_DEFAULT_NOTE_TTL_SECONDS ?? 3600), defaultNoteNoExpiration: import.meta.env.VITE_DEFAULT_NOTE_NO_EXPIRATION === 'true', isSettingNoExpirationAllowed: import.meta.env.VITE_IS_SETTING_NO_EXPIRATION_ALLOWED === 'true', + noteBaseUrl: import.meta.env.VITE_NOTE_BASE_URL ?? window.location.origin, }; diff --git a/packages/app-client/src/modules/config/config.types.ts b/packages/app-client/src/modules/config/config.types.ts index e65a33a2..da6f9d31 100644 --- a/packages/app-client/src/modules/config/config.types.ts +++ b/packages/app-client/src/modules/config/config.types.ts @@ -7,4 +7,5 @@ export type Config = { defaultNoteTtlSeconds: number; isSettingNoExpirationAllowed: boolean; defaultNoteNoExpiration: boolean; + noteBaseUrl: string; }; diff --git a/packages/app-client/src/modules/notes/pages/create-note.page.tsx b/packages/app-client/src/modules/notes/pages/create-note.page.tsx index 9365307d..0a023abb 100644 --- a/packages/app-client/src/modules/notes/pages/create-note.page.tsx +++ b/packages/app-client/src/modules/notes/pages/create-note.page.tsx @@ -124,6 +124,10 @@ export const CreateNotePage: Component = () => { const [getIsNoteCreating, setIsNoteCreating] = createSignal(false); const [getHasNoExpiration, setHasNoExpiration] = createSignal(config.defaultNoteNoExpiration); + function replaceBaseUrl(url: string, newBaseUrl: string): string { + return url.replace(/^(https?:\/\/)?([^\/:]+)(:\d+)?/, newBaseUrl); +} + function resetNoteForm() { setContent(''); setPassword(''); @@ -172,7 +176,9 @@ export const CreateNotePage: Component = () => { if (!error) { const { noteUrl } = createdNote; - setNoteUrl(noteUrl); + const newNoteUrl = replaceBaseUrl(noteUrl, config.noteBaseUrl); + + setNoteUrl(newNoteUrl); setIsNoteCreated(true); return; } diff --git a/packages/app-server/src/modules/app/config/config.ts b/packages/app-server/src/modules/app/config/config.ts index 28706947..90badb6f 100644 --- a/packages/app-server/src/modules/app/config/config.ts +++ b/packages/app-server/src/modules/app/config/config.ts @@ -200,6 +200,12 @@ export const configDefinition = { default: 'false', env: 'PUBLIC_DEFAULT_NOTE_NO_EXPIRATION', }, + noteBaseUrl: { + doc: 'The base URL to access the note link', + schema: z.string(), + default: '', + env: 'PUBLIC_NOTE_BASE_URL', + } }, authentication: { jwtSecret: {