Skip to content

Commit

Permalink
feat(ui): add support for custom note share base url
Browse files Browse the repository at this point in the history
  • Loading branch information
panjd123 committed Jan 9, 2025
1 parent dbc52a6 commit 0d302b9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/app-client/src/modules/config/config.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
1 change: 1 addition & 0 deletions packages/app-client/src/modules/config/config.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export type Config = {
defaultNoteTtlSeconds: number;
isSettingNoExpirationAllowed: boolean;
defaultNoteNoExpiration: boolean;
noteBaseUrl: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 128 in packages/app-client/src/modules/notes/pages/create-note.page.tsx

View workflow job for this annotation

GitHub Actions / CI - App Client

Unnecessary escape character: \/
}

Check failure on line 129 in packages/app-client/src/modules/notes/pages/create-note.page.tsx

View workflow job for this annotation

GitHub Actions / CI - App Client

Expected indentation of 2 spaces but found 0

function resetNoteForm() {
setContent('');
setPassword('');
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/app-server/src/modules/app/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Check failure on line 208 in packages/app-server/src/modules/app/config/config.ts

View workflow job for this annotation

GitHub Actions / CI - App Server

Missing trailing comma
},
authentication: {
jwtSecret: {
Expand Down

0 comments on commit 0d302b9

Please sign in to comment.