pranav8tripathi@gmail.com commited on
Commit
8563afe
·
1 Parent(s): 5d0ef8c
Files changed (2) hide show
  1. Dockerfile +15 -21
  2. vite.config.ts +27 -34
Dockerfile CHANGED
@@ -2,42 +2,36 @@
2
  FROM node:20-alpine AS builder
3
  WORKDIR /app
4
 
5
- # Install build dependencies
6
  RUN apk add --no-cache python3 make g++
7
 
8
- # Copy package files
9
  COPY package*.json ./
 
10
 
11
- # Install all dependencies including devDependencies
12
- RUN npm install
13
-
14
- # Copy the rest of the application
15
  COPY . .
16
-
17
- # Build the application
18
  RUN npm run build
19
 
20
  # Production stage
21
  FROM node:20-alpine
22
  WORKDIR /app
23
 
24
- # Copy package files
25
- COPY package*.json ./
26
-
27
- # Install only production dependencies
28
- RUN npm ci --omit=dev
29
-
30
- # Copy built assets from builder
31
  COPY --from=builder /app/dist ./dist
32
 
33
- # Copy other necessary files (like public folder if exists)
34
- COPY public ./public
 
 
 
35
 
36
- # Switch to non-root user
37
  USER node
38
 
39
- # Expose the port the app runs on
 
40
  EXPOSE 7860
41
 
42
- # Run the Vite preview server
43
- CMD ["npx", "vite", "preview", "--host", "--port", "7860"]
 
2
  FROM node:20-alpine AS builder
3
  WORKDIR /app
4
 
5
+ # If you have native deps, keep these; otherwise you can remove
6
  RUN apk add --no-cache python3 make g++
7
 
8
+ # Install deps with lockfile if available
9
  COPY package*.json ./
10
+ RUN npm ci
11
 
12
+ # Copy source and build
 
 
 
13
  COPY . .
 
 
14
  RUN npm run build
15
 
16
  # Production stage
17
  FROM node:20-alpine
18
  WORKDIR /app
19
 
20
+ # Copy built assets
 
 
 
 
 
 
21
  COPY --from=builder /app/dist ./dist
22
 
23
+ # Copy Vite config so preview.allowedHosts is applied
24
+ COPY vite.config.* ./
25
+
26
+ # Install Vite to run the preview server at runtime
27
+ RUN npm i --no-save vite@^5
28
 
29
+ # Non-root user
30
  USER node
31
 
32
+ # Hugging Face listens on PORT (default 7860)
33
+ ENV PORT=7860
34
  EXPOSE 7860
35
 
36
+ # Serve the built app with Vite preview
37
+ CMD ["sh", "-c", "node node_modules/vite/bin/vite.js preview --host 0.0.0.0 --port ${PORT:-7860}"]
vite.config.ts CHANGED
@@ -1,40 +1,33 @@
1
- import { defineConfig } from 'vite'
2
- import react from '@vitejs/plugin-react'
3
  import path from 'path'
4
 
5
- export default defineConfig({
6
- plugins: [react()],
7
- resolve: {
8
- alias: {
9
- '@': path.resolve(__dirname, './src'),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  },
11
- },
12
- server: {
13
- host: '0.0.0.0',
14
- port: 3000,
15
- strictPort: true,
16
- hmr: {
17
- host: 'pranav8tripathi-chopfresh.hf.space',
18
- protocol: 'wss',
19
- port: 443
20
- }
21
- },
22
- preview: {
23
- host: true,
24
- port: 7860,
25
- strictPort: true,
26
- allowedHosts: ['pranav8tripathi-chopfresh.hf.space'], // ✅ Add this line
27
- headers: {
28
- 'Access-Control-Allow-Origin': '*',
29
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
30
- 'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization'
31
  },
32
- proxy: {
33
- '^/.*': {
34
- target: 'http://localhost:3000',
35
- changeOrigin: true,
36
- secure: false
37
- }
38
- }
39
  }
40
  })
 
1
+ import { defineConfig, ConfigEnv } from 'vite'
 
2
  import path from 'path'
3
 
4
+ // Dynamic config so we don't require @vitejs/plugin-react during "preview"
5
+ export default defineConfig(async ({ command }: ConfigEnv) => {
6
+ const plugins = []
7
+ if (command !== 'preview') {
8
+ const { default: react } = await import('@vitejs/plugin-react')
9
+ plugins.push(react())
10
+ }
11
+
12
+ return {
13
+ plugins,
14
+ resolve: {
15
+ alias: {
16
+ '@': path.resolve(__dirname, './src'),
17
+ },
18
+ },
19
+ // Local dev only
20
+ server: {
21
+ host: '0.0.0.0',
22
+ port: 3000,
23
+ strictPort: true,
24
  },
25
+ // Used on Hugging Face (production)
26
+ preview: {
27
+ host: '0.0.0.0',
28
+ port: 7860,
29
+ strictPort: true,
30
+ allowedHosts: ['pranav8tripathi-chopfresh.hf.space'],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  },
 
 
 
 
 
 
 
32
  }
33
  })