Skip to content

Commit eb51313

Browse files
authored
feat: vite proxy (#27)
* feat: testing vite proxy config * fix: docker build * build: fix health endpoint to be frontend only * debug docker container * cont debug docker exit * more debugging * and more debugging * more localhost debugging * chore: clean up debugging * fix: allowed hosts * testing vite config * testing vite logs * more testing * fix: proxy * testing env var * fix: auth proxy * fixing auth verify * testing redirect on success * fix company
1 parent 163f790 commit eb51313

5 files changed

Lines changed: 478 additions & 55 deletions

File tree

Dockerfile

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,73 +22,65 @@ COPY . .
2222
# Build the application
2323
RUN pnpm run build
2424

25-
# Stage 2: Production server
26-
FROM nginx:alpine
27-
28-
# Simple nginx config for EasyPanel (no API proxy - EasyPanel handles routing)
29-
COPY <<EOF /etc/nginx/conf.d/default.conf
30-
server {
31-
listen 80;
32-
server_name _;
33-
root /usr/share/nginx/html;
34-
index index.html;
35-
36-
# Handle React Router - all routes should serve index.html
37-
location / {
38-
try_files \$uri \$uri/ /index.html;
39-
}
40-
41-
# Health check for EasyPanel monitoring
42-
location /health {
43-
access_log off;
44-
return 200 "healthy";
45-
add_header Content-Type text/plain;
46-
}
47-
48-
# Basic security headers
49-
add_header X-Frame-Options "SAMEORIGIN";
50-
add_header X-Content-Type-Options "nosniff";
51-
52-
# Enable gzip compression
53-
gzip on;
54-
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
55-
}
56-
EOF
25+
# Stage 2: Production server using Vite preview
26+
FROM node:18-alpine
27+
28+
# Set working directory
29+
WORKDIR /app
5730

58-
# Copy built application from build stage
59-
COPY --from=build /app/dist /usr/share/nginx/html
31+
# Install pnpm globally
32+
RUN npm install -g pnpm@9.0.0
33+
34+
# Copy built application and necessary files from build stage
35+
COPY --from=build /app/dist ./dist
36+
COPY --from=build /app/package.json ./package.json
37+
COPY --from=build /app/pnpm-lock.yaml ./pnpm-lock.yaml
38+
COPY --from=build /app/vite.config.ts ./vite.config.ts
39+
COPY --from=build /app/tsconfig.json ./tsconfig.json
40+
COPY --from=build /app/tsconfig.node.json ./tsconfig.node.json
41+
42+
# Install all dependencies (needed for Vite preview with config)
43+
RUN pnpm install --frozen-lockfile
6044

6145
# Copy docker entrypoint script
6246
COPY <<EOF /docker-entrypoint.sh
6347
#!/bin/sh
6448

6549
# Simple startup logging
66-
echo "🚀 Starting Unified Arda Platform"
50+
echo "🚀 Starting Unified Arda Platform with Vite Preview Server"
6751
echo "Backend: \${VITE_SERVER_URL:-http://localhost:8080}"
52+
echo "Chat Agent: \${VITE_CHAT_AGENT_URL:-http://localhost:3002}"
53+
echo "Environment: \${VITE_SERVER_ENVIRONMENT:-production}"
6854

6955
# Inject environment variables into the built app
70-
# This allows runtime configuration changes without rebuilding
71-
cat > /usr/share/nginx/html/env-config.js << EOL
56+
cat > /app/dist/env-config.js << EOL
7257
window.__ENV__ = {
73-
VITE_SERVER_URL: "\${VITE_SERVER_URL:-http://backend:8080}",
58+
VITE_SERVER_URL: "\${VITE_SERVER_URL:-http://arda-credit_server:8080}",
7459
VITE_SERVER_ENVIRONMENT: "\${VITE_SERVER_ENVIRONMENT:-production}",
75-
VITE_CHAT_AGENT_URL: "\${VITE_CHAT_AGENT_URL:-http://chat-agent:3002}",
60+
VITE_CHAT_AGENT_URL: "\${VITE_CHAT_AGENT_URL:-http://arda-credit_chat-agent:3002}",
7661
VITE_ETHEREUM_RPC_URL: "\${VITE_ETHEREUM_RPC_URL:-http://127.0.0.1:8545}"
7762
};
7863
EOL
7964

80-
echo "✅ Environment injected, starting nginx..."
81-
exec nginx -g 'daemon off;'
65+
echo "✅ Environment injected, starting Vite preview server..."
66+
echo "Server will be available on http://0.0.0.0:3000"
67+
68+
# Start Vite preview server
69+
echo "🚀 Starting Vite preview server on http://0.0.0.0:3000"
70+
echo "✅ Proxy configuration active for all backend services"
71+
72+
# Run Vite preview server in foreground - Docker health check handles verification
73+
exec pnpm run preview --host 0.0.0.0 --port 3000
8274
EOF
8375

8476
# Make entrypoint executable
8577
RUN chmod +x /docker-entrypoint.sh
8678

87-
# Expose port 80
88-
EXPOSE 80
79+
# Expose port 3000 (Vite preview default)
80+
EXPOSE 3000
8981

90-
# Simple health check for EasyPanel
91-
HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD wget --no-verbose --tries=1 --spider http://localhost/health || exit 1
82+
# Health check for container monitoring
83+
HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=30s CMD wget --quiet --tries=1 --spider http://127.0.0.1:3000/ || exit 1
9284

9385
# Set entrypoint
9486
ENTRYPOINT ["/docker-entrypoint.sh"]

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
"check-types": "tsc --noEmit",
1313
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
1414
"docker:build": "docker build -t arda-platform:latest .",
15-
"docker:run": "docker run -d -p 3000:80 --name arda-platform arda-platform:latest",
15+
"docker:run": "docker run -d -p 3000:3000 --name arda-platform arda-platform:latest",
16+
"docker:run:dev": "docker run -d -p 3000:3000 -e VITE_SERVER_URL=http://localhost:8080 -e VITE_CHAT_AGENT_URL=http://localhost:3002 --name arda-platform arda-platform:latest",
1617
"docker:stop": "docker stop arda-platform && docker rm arda-platform",
1718
"docker:logs": "docker logs -f arda-platform",
19+
"docker:exec": "docker exec -it arda-platform sh",
1820
"docker:tag": "docker tag arda-platform:latest ghcr.io/ardaglobal/arda-platform:latest",
1921
"docker:push": "docker push ghcr.io/ardaglobal/arda-platform:latest",
2022
"docker:deploy": "npm run docker:build && npm run docker:tag && npm run docker:push"
@@ -69,6 +71,7 @@
6971
"tailwind-merge": "^2.6.0",
7072
"tailwindcss-animate": "^1.0.7",
7173
"vaul": "^0.9.9",
74+
"vite": "^5.4.19",
7275
"zod": "^3.25.76"
7376
},
7477
"devDependencies": {
@@ -88,8 +91,7 @@
8891
"prettier": "^3.6.2",
8992
"tailwindcss": "^3.4.17",
9093
"typescript": "^5.8.3",
91-
"typescript-eslint": "^8.38.0",
92-
"vite": "^5.4.19"
94+
"typescript-eslint": "^8.38.0"
9395
},
9496
"packageManager": "pnpm@9.0.0",
9597
"engines": {

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/shared/config/runtime.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,27 @@ declare global {
2121
}
2222

2323
export const getConfig = (): RuntimeConfig => {
24-
// In production, read from window.__ENV__ (injected at container startup)
25-
// In development, fall back to import.meta.env
24+
// Check if we're in production (served over HTTPS) - use relative paths to avoid mixed content
25+
const isProduction = typeof window !== 'undefined' && window.location.protocol === 'https:';
26+
27+
console.log('🔧 Runtime Config:', {
28+
isProduction,
29+
hasWindowEnv: typeof window !== 'undefined' && !!window.__ENV__,
30+
protocol: typeof window !== 'undefined' ? window.location.protocol : 'unknown'
31+
});
32+
33+
if (isProduction) {
34+
console.log('🚀 Production mode detected - using relative URLs for API requests');
35+
return {
36+
SERVER_URL: '', // Empty string = relative paths like /api/v1/auth/me
37+
CREDIT_APP_URL: window.__ENV__?.VITE_CREDIT_APP_URL || 'http://localhost:3000',
38+
IDR_URL: window.__ENV__?.VITE_IDR_URL || 'http://localhost:3001',
39+
};
40+
}
41+
42+
// In development or when window.__ENV__ exists but not HTTPS
2643
if (typeof window !== 'undefined' && window.__ENV__) {
44+
console.log('🛠️ Using window.__ENV__ configuration for development/staging');
2745
return {
2846
SERVER_URL: window.__ENV__.VITE_SERVER_URL || 'http://localhost:8080',
2947
CREDIT_APP_URL: window.__ENV__.VITE_CREDIT_APP_URL || 'http://localhost:3000',
@@ -32,6 +50,7 @@ export const getConfig = (): RuntimeConfig => {
3250
}
3351

3452
// Development fallback - no path prefixes for local dev with pnpm dev
53+
console.log('🔨 Using import.meta.env fallback for local development');
3554
return {
3655
SERVER_URL: import.meta.env.VITE_SERVER_URL || 'http://localhost:8080',
3756
CREDIT_APP_URL: import.meta.env.VITE_CREDIT_APP_URL || 'http://localhost:3000',

0 commit comments

Comments
 (0)