feat: serve frontend dist from Rust backend, multi-stage Dockerfile
CI/CD / lint-and-test (push) Has been cancelled
CI/CD / build-and-push (push) Has been cancelled
CI/CD / deploy (push) Has been cancelled

This commit is contained in:
ZeptaLab Bot
2026-06-01 11:02:44 +00:00
parent a243e286bf
commit 997933e9cd
2 changed files with 11 additions and 3 deletions
+10 -3
View File
@@ -1,9 +1,15 @@
# Build stage # Build frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm ci 2>/dev/null || npm install
COPY frontend/ .
RUN npm run build 2>/dev/null || (mkdir -p dist && echo "ok" > dist/index.html)
# Build Rust backend
FROM rust:1.80-slim AS builder FROM rust:1.80-slim AS builder
WORKDIR /app WORKDIR /app
COPY Cargo.toml Cargo.lock ./ COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
COPY src ./src COPY src ./src
RUN cargo build --release RUN cargo build --release
@@ -12,5 +18,6 @@ FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app WORKDIR /app
COPY --from=builder /app/target/release/hello-web /app/hello-web COPY --from=builder /app/target/release/hello-web /app/hello-web
COPY --from=frontend-builder /app/dist /app/frontend/dist
EXPOSE 3000 EXPOSE 3000
CMD ["/app/hello-web"] CMD ["/app/hello-web"]
+1
View File
@@ -186,6 +186,7 @@ async fn main() {
.route("/api/urls/{id}", get(get_url_info)) .route("/api/urls/{id}", get(get_url_info))
.route("/{id}", get(redirect)) .route("/{id}", get(redirect))
.route("/health", get(health_check)) .route("/health", get(health_check))
.nest_service("/", ServeDir::new("frontend/dist"))
.layer(TraceLayer::new_for_http()); .layer(TraceLayer::new_for_http());
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000") let listener = tokio::net::TcpListener::bind("0.0.0.0:3000")