server be & fe
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import react from '@vitejs/plugin-react';
|
||||
import { defineConfig, loadEnv, type ProxyOptions } from 'vite';
|
||||
|
||||
// Behind the real reverse proxy /api never reaches this server. The /api proxy below only emulates
|
||||
// that reverse proxy for local development without it (strips /api, sets X-Forwarded-Prefix).
|
||||
//
|
||||
// Env (server-fe/.env or process env):
|
||||
// ALLOWED_HOSTS comma-separated public host names (default dev.aggtaa.com)
|
||||
// BACKEND_URL local dev: server-be address (default http://127.0.0.1:10002)
|
||||
// ADMIN_PROXY_SECRET local dev: sent as X-Cardy-Proxy-Secret, must match server-be
|
||||
// DEV_REMOTE_EMAIL local dev: fakes the Remote-Email header normally set by Authelia
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '');
|
||||
const headers: Record<string, string> = { 'X-Forwarded-Prefix': '/api' };
|
||||
if (env.ADMIN_PROXY_SECRET) headers['X-Cardy-Proxy-Secret'] = env.ADMIN_PROXY_SECRET;
|
||||
if (env.DEV_REMOTE_EMAIL) {
|
||||
headers['Remote-Email'] = env.DEV_REMOTE_EMAIL;
|
||||
console.warn(`\n⚠ DEV_REMOTE_EMAIL is set: every request acts as ${env.DEV_REMOTE_EMAIL}. Never use it behind the real proxy.\n`);
|
||||
}
|
||||
|
||||
const proxy: Record<string, ProxyOptions> = {
|
||||
'/api': {
|
||||
target: env.BACKEND_URL || 'http://127.0.0.1:10002',
|
||||
rewrite: (path) => path.replace(/^\/api/, '') || '/',
|
||||
headers,
|
||||
},
|
||||
};
|
||||
const server = {
|
||||
host: true,
|
||||
port: 10001,
|
||||
strictPort: true,
|
||||
allowedHosts: (env.ALLOWED_HOSTS || 'dev.aggtaa.com').split(',').map((h) => h.trim()),
|
||||
proxy,
|
||||
};
|
||||
|
||||
return {
|
||||
plugins: [react()],
|
||||
// bwip-js alone is ~1 MB; it is lazy-loaded.
|
||||
build: { chunkSizeWarningLimit: 1100 },
|
||||
server,
|
||||
preview: server,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user