-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
92 lines (79 loc) · 2.51 KB
/
Copy pathvite.config.ts
File metadata and controls
92 lines (79 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// Development and production CORS origins
const getDevelopmentCorsOrigins = () => [
'http://localhost:5173',
'http://localhost:3000',
'http://localhost:4173', // Vite preview server
'http://127.0.0.1:5173',
'http://127.0.0.1:3000',
'http://127.0.0.1:4173'
]
const getProductionCorsOrigins = () => [
'https://aau.co.ug',
'https://www.aau.co.ug',
'https://automobile-association.vercel.app'
]
// Environment-based CORS configuration
const getCorsConfig = (mode: string) => {
const isDevelopment = mode === 'development'
return {
// Only allow production origins in production builds
// Development server should only accept local origins for security
origin: isDevelopment ? getDevelopmentCorsOrigins() : getProductionCorsOrigins(),
// Only enable credentials when necessary and in secure contexts
credentials: !isDevelopment, // Disable credentials in development for security
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'],
allowedHeaders: [
'Content-Type',
'Authorization',
'Accept',
'Origin',
'X-Requested-With',
'apikey' // For Supabase API key
],
// Security headers
optionsSuccessStatus: 200, // For legacy browser support
maxAge: isDevelopment ? 0 : 86400 // Cache preflight for 24h in production
}
}
// https://vite.dev/config/
export default defineConfig(({ mode }) => ({
plugins: [
react({
jsxImportSource: '@emotion/react',
babel: {
plugins: ['@emotion/babel-plugin']
}
})
],
optimizeDeps: {
include: ['@emotion/styled']
},
server: {
// Development server configuration
cors: getCorsConfig(mode),
// Additional security for development server
host: '127.0.0.1', // Restrict to localhost only
strictPort: true, // Don't auto-increment port if busy
// Headers for additional security
headers: {
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'X-XSS-Protection': '1; mode=block'
}
},
// Production build optimizations
build: {
// Security-focused build options
sourcemap: mode === 'development', // Only generate sourcemaps in development
minify: mode === 'production' ? 'esbuild' : false,
// Remove console logs in production
terserOptions: mode === 'production' ? {
compress: {
drop_console: true,
drop_debugger: true
}
} : undefined
}
}))