Skip to content

Commit 5f14813

Browse files
committed
fix: runtime envsubst and SPA routing for web library
1 parent fb115b3 commit 5f14813

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

Dockerfile.web-library

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ COPY app/web-library-upstream/ /app/web-library-upstream/
1010
COPY app/web-library-overlay/ /app/web-library-overlay/
1111

1212
# Apply overlay into a build directory
13-
RUN apt-get update \
14-
&& apt-get install -y --no-install-recommends rsync gettext-base \
15-
&& rm -rf /var/lib/apt/lists/* \
16-
&& mkdir -p /app/web-library-build \
13+
RUN mkdir -p /app/web-library-build \
1714
&& rsync -a /app/web-library-upstream/ /app/web-library-build/ \
1815
&& if [ -d /app/web-library-overlay/src ]; then rsync -a /app/web-library-overlay/src/ /app/web-library-build/src/; fi \
1916
&& if [ -d /app/web-library-overlay/config ]; then rsync -a /app/web-library-overlay/config/ /app/web-library-build/config/; fi
@@ -27,29 +24,22 @@ RUN git clone --depth 1 --recurse-submodules --shallow-submodules https://github
2724
&& git clone --depth 1 --recurse-submodules --shallow-submodules https://github.com/zotero/web-common.git modules/web-common \
2825
&& git clone --depth 1 --recurse-submodules --shallow-submodules https://github.com/zotero/zotero-schema.git modules/zotero-schema
2926

30-
# Inject build-time metadata config for overlay (api key/authority, user slug/id, pdf proxy base)
31-
ARG ZOTERO_API_KEY=""
32-
ARG ZOTERO_API_AUTHORITY_PART="api.zotero.org"
33-
ARG ZOTERO_USER_SLUG=""
34-
ARG ZOTERO_USER_ID="0"
35-
ARG PDF_PROXY_BASE_URL="http://localhost:8280/pdf"
36-
ENV ZOTERO_API_KEY=$ZOTERO_API_KEY \
37-
ZOTERO_API_AUTHORITY_PART=$ZOTERO_API_AUTHORITY_PART \
38-
ZOTERO_USER_SLUG=$ZOTERO_USER_SLUG \
39-
ZOTERO_USER_ID=$ZOTERO_USER_ID \
40-
PDF_PROXY_BASE_URL=$PDF_PROXY_BASE_URL
41-
42-
RUN envsubst < /app/web-library-overlay/src/html/index.html > /app/web-library-build/src/html/index.html
43-
4427
# Build Web Library (combined subtree + overlay)
4528
RUN npm ci \
4629
&& npm run build
4730

4831
# Runtime: serve static assets via nginx
4932
FROM nginx:1.27-alpine AS runtime
5033

34+
# For envsubst and clean startup
35+
RUN apk add --no-cache gettext
36+
5137
COPY --from=builder /app/web-library-build/build/ /usr/share/nginx/html/
38+
COPY app/web-library-overlay/config/nginx.conf /etc/nginx/conf.d/default.conf
39+
COPY app/web-library-overlay/scripts/entrypoint.sh /entrypoint.sh
40+
RUN chmod +x /entrypoint.sh
5241

5342
EXPOSE 80
5443

44+
ENTRYPOINT ["/entrypoint.sh"]
5545
CMD ["nginx", "-g", "daemon off;"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
5+
root /usr/share/nginx/html;
6+
index index.html;
7+
8+
location / {
9+
try_files $uri $uri/ /index.html;
10+
}
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env sh
2+
set -e
3+
4+
# Defaults for runtime substitution
5+
: "${ZOTERO_API_KEY:=}"
6+
: "${ZOTERO_API_AUTHORITY_PART:=api.zotero.org}"
7+
: "${ZOTERO_USER_SLUG:=zotero-user}"
8+
: "${ZOTERO_USER_ID:=0}"
9+
: "${PDF_PROXY_BASE_URL:=http://localhost:8280/pdf}"
10+
11+
# Render index.html with current env vars (placeholders remain if empty)
12+
if [ -f /usr/share/nginx/html/index.html ]; then
13+
envsubst \
14+
'$ZOTERO_API_KEY $ZOTERO_API_AUTHORITY_PART $ZOTERO_USER_SLUG $ZOTERO_USER_ID $PDF_PROXY_BASE_URL' \
15+
< /usr/share/nginx/html/index.html \
16+
> /usr/share/nginx/html/index.html.rendered
17+
mv /usr/share/nginx/html/index.html.rendered /usr/share/nginx/html/index.html
18+
fi
19+
20+
exec "$@"

0 commit comments

Comments
 (0)