34 lines
957 B
JavaScript
34 lines
957 B
JavaScript
import { defineConfig, loadEnv } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
// Dev mode: proxy /api/* to api.workolik.com and inject x-hasura-admin-secret
|
|
// server-side so the secret never reaches the browser.
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
const secret = (env.HASURA_ADMIN_SECRET || '').trim()
|
|
|
|
if (!secret) {
|
|
console.warn('[xpress-docs] HASURA_ADMIN_SECRET is not set in .env.local; proxied requests will hit the API without auth.')
|
|
}
|
|
|
|
return {
|
|
plugins: [react()],
|
|
server: {
|
|
port: 5173,
|
|
open: true,
|
|
proxy: {
|
|
'/api': {
|
|
target: 'https://api.workolik.com',
|
|
changeOrigin: true,
|
|
secure: true,
|
|
configure: (proxy) => {
|
|
proxy.on('proxyReq', (proxyReq) => {
|
|
if (secret) proxyReq.setHeader('x-hasura-admin-secret', secret)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|