From 96fbbb5714187306057612b38d7711bf7d26ebfa Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Mon, 21 Jul 2025 12:25:21 +0200 Subject: [PATCH] #112 Improve og:image base URL function --- README.md | 11 +++++++++-- app/config.json | 1 - app/src/render.ts | 2 +- docker-compose.yml | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e75fc9e..1888d7c 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,9 @@ Here is an example setup for [securing Immich behind mTLS](./docs/securing-immic 2. Update the value for `IMMICH_URL` in your docker-compose file to point to your local URL for Immich. This should not be a public URL. -3. Start the docker container. You can test that it is working by visiting `https://your-proxy-url.com/share/healthcheck`. +3. Update the value for `PUBLIC_BASE_URL` to be the public base URL for IPP, without a trailing slash (example `https://your-proxy-url.com`). + +4. Start the docker container. You can test that it is working by visiting `https://your-proxy-url.com/share/healthcheck`. Check the container console output for any error messages. ```bash @@ -142,7 +144,6 @@ There are some additional configuration options you can change, for example the | Option | Type | Description | |-------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `publicBaseUrl` | `string` | Set this to be the base public URL of your IPP instance. This is used for generating the `og:image` URL. If you want to use multiple public URLs, you can instead set this value to `null` and send a `publicBaseUrl` header on the request from your reverse proxy to IPP. | | `responseHeaders` | `object` | Change the headers sent with your web responses. By default there is `cache-control` and CORS added. | | `singleImageGallery` | `bool` | By default a link to a single image will directly open the image file. Set to `true` if you want to show a gallery page instead for a single item. | | `downloadOriginalPhoto` | `bool` | Set to `false` if you only want people to be able to download the 'preview' quality photo, rather than your original photo. | @@ -203,6 +204,12 @@ You can customise the responses that IPP sends for invalid requests. For example See [Custom responses](docs/custom-responses.md) for more details. +### Serving from multiple domains + +If you're serving the same IPP from multiple domains, instead of setting the public URL in your docker-compose file, you can set it dynamically via a HTTP header in the request from your reverse proxy to IPP. + +Set a custom `publicBaseUrl` header on each request with the value of your public base URL (example `https://your-proxy-url.com`). + ## Troubleshooting ### Video playback diff --git a/app/config.json b/app/config.json index 5fdf6d3..a3413cb 100644 --- a/app/config.json +++ b/app/config.json @@ -1,6 +1,5 @@ { "ipp": { - "publicBaseUrl": "https://your-proxy-url.com", "responseHeaders": { "Cache-Control": "public, max-age=2592000", "Access-Control-Allow-Origin": "*" diff --git a/app/src/render.ts b/app/src/render.ts index 45e80c2..c0775d0 100644 --- a/app/src/render.ts +++ b/app/src/render.ts @@ -91,7 +91,7 @@ class Render { // publicBaseUrl is used for the og:image, which requires a fully qualified URL. // You can specify this in your config.json file, or send it dynamically as a `host` header - const publicBaseUrl = getConfigOption('ipp.publicBaseUrl', null) || res.req.headers.publicBaseUrl || '' + const publicBaseUrl = process.env.PUBLIC_BASE_URL || res.req.headers.publicBaseUrl || (res.req.protocol + '://' + res.req.headers.host) for (const asset of share.assets) { let video, downloadUrl diff --git a/docker-compose.yml b/docker-compose.yml index 9b6c994..d4147f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: ports: - "3000:3000" environment: + - PUBLIC_BASE_URL=https://your-proxy-url.com - IMMICH_URL=http://your-internal-immich-server:2283 healthcheck: test: curl -s http://localhost:3000/share/healthcheck -o /dev/null || exit 1