Skip to content

Commit 3c6e9e1

Browse files
authored
feat: use request host as default SSR domain (#19485)
fix: hostname and domain confusion chore: e2e test
1 parent db0415b commit 3c6e9e1

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

e2e/src/api/specs/shared-link.e2e-spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ describe('/shared-links', () => {
117117
const resp = await request(shareUrl).get(`/${linkWithAssets.key}`);
118118
expect(resp.status).toBe(200);
119119
expect(resp.header['content-type']).toContain('text/html');
120+
expect(resp.text).toContain(`<meta property="og:image" content="http://127.0.0.1:2285`);
121+
});
122+
123+
it('should fall back to my.immich.app og:image meta tag for shared asset if Host header is not present', async () => {
124+
const resp = await request(shareUrl).get(`/${linkWithAssets.key}`).set('Host', '');
125+
expect(resp.status).toBe(200);
126+
expect(resp.header['content-type']).toContain('text/html');
120127
expect(resp.text).toContain(`<meta property="og:image" content="https://my.immich.app`);
121128
});
122129

server/src/services/api.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ export class ApiService {
8686
try {
8787
const key = shareMatches[1];
8888
const auth = await this.authService.validateSharedLink(key);
89-
const meta = await this.sharedLinkService.getMetadataTags(auth);
89+
const meta = await this.sharedLinkService.getMetadataTags(
90+
auth,
91+
request.host ? `${request.protocol}://${request.host}` : undefined,
92+
);
9093
if (meta) {
9194
html = render(index, meta);
9295
}

server/src/services/shared-link.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class SharedLinkService extends BaseService {
174174
return results;
175175
}
176176

177-
async getMetadataTags(auth: AuthDto): Promise<null | OpenGraphTags> {
177+
async getMetadataTags(auth: AuthDto, defaultDomain?: string): Promise<null | OpenGraphTags> {
178178
if (!auth.sharedLink || auth.sharedLink.password) {
179179
return null;
180180
}
@@ -190,7 +190,7 @@ export class SharedLinkService extends BaseService {
190190
return {
191191
title: sharedLink.album ? sharedLink.album.albumName : 'Public Share',
192192
description: sharedLink.description || `${assetCount} shared photos & videos`,
193-
imageUrl: new URL(imagePath, getExternalDomain(config.server)).href,
193+
imageUrl: new URL(imagePath, getExternalDomain(config.server, defaultDomain)).href,
194194
};
195195
}
196196

server/src/utils/misc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export const getMethodNames = (instance: any) => {
4444
return methods;
4545
};
4646

47-
export const getExternalDomain = (server: SystemConfig['server']) => server.externalDomain || `https://my.immich.app`;
47+
export const getExternalDomain = (server: SystemConfig['server'], defaultDomain = 'https://my.immich.app') =>
48+
server.externalDomain || defaultDomain;
4849

4950
/**
5051
* @returns a list of strings representing the keys of the object in dot notation

0 commit comments

Comments
 (0)