Skip to content

Commit

Permalink
Added support for base href customization
Browse files Browse the repository at this point in the history
  • Loading branch information
tk-nguyen committed Sep 26, 2024
1 parent 428b638 commit c914dc1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN nix build -v --extra-experimental-features flakes --extra-experimental-featu

# Building Twake for the web
FROM --platform=linux/amd64 ghcr.io/cirruslabs/flutter:${FLUTTER_VERSION} AS web-builder
ARG TWAKECHAT_BASE_HREF="/web/"
COPY . /app
WORKDIR /app
RUN DEBIAN_FRONTEND=noninteractive apt update && \
Expand All @@ -22,8 +23,11 @@ RUN --mount=type=ssh,required=true ./scripts/build-web.sh

# Final image
FROM nginx:alpine AS final-image
ARG TWAKECHAT_BASE_HREF
ENV TWAKECHAT_BASE_HREF=${TWAKECHAT_BASE_HREF:-/web/}
RUN rm -rf /usr/share/nginx/html
COPY --from=web-builder /app/build/web /usr/share/nginx/html/web/
COPY --from=web-builder /app/build/web /usr/share/nginx/html${TWAKECHAT_BASE_HREF}
COPY ./configurations/nginx.conf.template /etc/nginx/templates/default.conf.template

# Specify the port
EXPOSE 80
13 changes: 13 additions & 0 deletions configurations/nginx.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
server {
listen 80;

location = / {
return 301 ${TWAKECHAT_BASE_HREF};
}

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
3 changes: 2 additions & 1 deletion scripts/build-web.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh -ve
TWAKECHAT_BASE_HREF=${TWAKECHAT_BASE_HREF:-/web/}
flutter config --enable-web
flutter clean
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
flutter build web --release --verbose --source-maps --base-href="/web/"
flutter build web --release --verbose --source-maps --base-href="$TWAKECHAT_BASE_HREF"
cp config.sample.json ./build/web/config.json

0 comments on commit c914dc1

Please sign in to comment.