Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): handle trailing slash in external domain #6253

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/src/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const copyToClipboard = async (secret: string) => {
};

export const makeSharedLinkUrl = (externalDomain: string, key: string) => {
return `${externalDomain || window.location.origin}/share/${key}`;
const url = externalDomain || window.location.origin;
return `${url + url.endsWith('/') ? '' : '/'}share/${key}`;
Comment on lines +23 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use a URL constructor instead? I believe this should work (untested):

Suggested change
const url = externalDomain || window.location.origin;
return `${url + url.endsWith('/') ? '' : '/'}share/${key}`;
const base = externalDomain || window.location.origin;
return new URL(`/share/${key}`, base).href;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's very well possible. I only did a quick google search (less than 1 minute lol) and people were like "yea, regex" lol
I'll test it real quick

Copy link
Member Author

@danieldietzler danieldietzler Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this doesn't work if your domain has a path as well (so immich.app/public/). Not sure if that's common though...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, though at the moment it's not possible to run Immich under a path anyways.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not possible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't tested with it and I think there are some things that don't work with it like goto(/photos)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that there are absolute paths but I was thinking you could have proxy rewrite rules for that stuff. Or well, at that point, you could also redirect /share to /public/share, nvm lol

};

export const oauth = {
Expand Down
Loading