Skip to content

Commit a15190f

Browse files
committed
fix(docker): resolve OG image ECONNREFUSED and EXIF WASM 404 in Docker
Closes #196
1 parent b631f03 commit a15190f

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎Dockerfile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ RUN sh ./scripts/preinstall.sh
2020
# Install all dependencies
2121
RUN pnpm install --frozen-lockfile
2222

23+
# Copy zeroperl.wasm to web public directory before build.
24+
# @uswriting/exiftool depends on @6over3/zeroperl-ts which loads zeroperl.wasm via fetch("./zeroperl.wasm")
25+
# relative to the current page URL, so it must be available under both root and /photos/ paths.
26+
RUN mkdir -p apps/web/public/photos && \
27+
find node_modules -name "zeroperl.wasm" -path "*/esm/*" -exec cp {} apps/web/public/ \; -exec cp {} apps/web/public/photos/ \; -quit
28+
2329
ARG S3_ACCESS_KEY_ID
2430
ARG S3_SECRET_ACCESS_KEY
2531
ARG GIT_TOKEN

‎apps/ssr/src/app/og/[photoId]/route.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
import { hostname } from 'node:os'
2+
13
import type { NextRequest } from 'next/server'
24

5+
function getDefaultCoreApiBase(): string {
6+
// In Docker, HOSTNAME is set to the container ID, and localhost may not resolve correctly (IPv6 issues).
7+
// Use os.hostname() which is resolvable within the Docker network.
8+
const isDocker = process.env.HOSTNAME && /^[a-f0-9]{12,64}$/.test(process.env.HOSTNAME)
9+
const host = isDocker ? hostname() : 'localhost'
10+
return `http://${host}:3000`
11+
}
12+
313
const CORE_API_BASE =
414
process.env.CORE_API_URL ??
515
process.env.NEXT_PUBLIC_CORE_API_URL ??
616
process.env.API_BASE_URL ??
7-
'http://localhost:3000'
17+
getDefaultCoreApiBase()
818

919
const FORWARDED_HEADER_KEYS = ['cookie', 'authorization', 'x-forwarded-host', 'x-forwarded-proto', 'host']
1020

0 commit comments

Comments
 (0)