41 lines
967 B
TypeScript
41 lines
967 B
TypeScript
import react from '@vitejs/plugin-react'
|
|
import path from 'node:path'
|
|
import { defineConfig, type ProxyOptions } from 'vite'
|
|
|
|
const apiProxyTarget = process.env.API_PROXY_TARGET ?? 'http://localhost:8000'
|
|
const apiProxyOrigin = new URL(process.env.API_PROXY_ORIGIN ?? apiProxyTarget)
|
|
|
|
function createApiProxy(): Record<string, string | ProxyOptions> {
|
|
return {
|
|
'/api': {
|
|
target: apiProxyTarget,
|
|
changeOrigin: true,
|
|
configure(proxy) {
|
|
proxy.on('proxyReq', (proxyRequest) => {
|
|
proxyRequest.setHeader('host', apiProxyOrigin.host)
|
|
proxyRequest.setHeader('origin', apiProxyOrigin.origin)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src')
|
|
}
|
|
},
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 5173,
|
|
proxy: createApiProxy()
|
|
},
|
|
preview: {
|
|
host: '0.0.0.0',
|
|
port: 4173,
|
|
proxy: createApiProxy()
|
|
}
|
|
})
|