Nothing12Man commited on
Commit
e92e954
Β·
1 Parent(s): 37eddd3

Add root route for HF Space homepage

Browse files
Files changed (2) hide show
  1. Dockerfile +15 -5
  2. lifeline-ai/next.config.js +14 -0
Dockerfile CHANGED
@@ -12,6 +12,9 @@ LABEL maintainer="MediRoute Team" \
12
  # ── System dependencies ───────────────────────────────────────────────────────
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
14
  curl \
 
 
 
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
  # ── Python runtime defaults ───────────────────────────────────────────────────
@@ -36,6 +39,14 @@ RUN if [ -f ./lifeline-backend-requirements.txt ]; then \
36
  # Copying the full project avoids file-not-found build breaks and is HF-Spaces-friendly.
37
  COPY . .
38
 
 
 
 
 
 
 
 
 
39
  # ── Non-root user for security ────────────────────────────────────────────────
40
  RUN adduser --disabled-password --gecos "" appuser
41
  USER appuser
@@ -46,10 +57,9 @@ ENV OPENAI_API_KEY="EMPTY" \
46
  MODEL_NAME="gpt-4o-mini" \
47
  HF_TOKEN=""
48
 
49
- # ── Expose the port expected by Hugging Face Spaces and run the backend web server
50
  EXPOSE 7860
51
 
52
- # Default command: start the FastAPI backend (lifeline-ai backend) on port 7860.
53
- # This keeps the container running as a web service compatible with Spaces (sdk: docker).
54
- # It will cd into the backend folder and run uvicorn. Override at runtime as needed.
55
- CMD ["sh", "-c", "uvicorn backend.app.main:app --host 0.0.0.0 --port 7860"]
 
12
  # ── System dependencies ───────────────────────────────────────────────────────
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
14
  curl \
15
+ ca-certificates \
16
+ gnupg \
17
+ build-essential \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
  # ── Python runtime defaults ───────────────────────────────────────────────────
 
39
  # Copying the full project avoids file-not-found build breaks and is HF-Spaces-friendly.
40
  COPY . .
41
 
42
+ # Install Node.js and build the Next.js frontend (do this as root before switching user)
43
+ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
44
+ && apt-get update && apt-get install -y --no-install-recommends nodejs \
45
+ && rm -rf /var/lib/apt/lists/* \
46
+ && cd lifeline-ai \
47
+ && npm ci --no-audit --no-fund || npm install \
48
+ && npm run build
49
+
50
  # ── Non-root user for security ────────────────────────────────────────────────
51
  RUN adduser --disabled-password --gecos "" appuser
52
  USER appuser
 
57
  MODEL_NAME="gpt-4o-mini" \
58
  HF_TOKEN=""
59
 
60
+ # ── Expose the port expected by Hugging Face Spaces (frontend)
61
  EXPOSE 7860
62
 
63
+ # Default command: start backend on 8000 (background) and run Next.js frontend on 7860
64
+ # The frontend proxies /api to the backend via next.config.js rewrites.
65
+ CMD ["sh", "-c", "uvicorn backend.app.main:app --host 127.0.0.1 --port 8000 & cd lifeline-ai && exec npm run start -- -p 7860"]
 
lifeline-ai/next.config.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Next.js configuration: proxy /api requests to the local FastAPI backend
3
+ * so the frontend can call /api/* and the backend remains accessible.
4
+ */
5
+ /** @type {import('next').NextConfig} */
6
+ module.exports = {
7
+ reactStrictMode: true,
8
+ async rewrites() {
9
+ return [
10
+ { source: '/api/:path*', destination: 'http://127.0.0.1:8000/:path*' },
11
+ { source: '/api', destination: 'http://127.0.0.1:8000/' },
12
+ ];
13
+ },
14
+ };