Files
travelplanning/frontend/vite.config.ts
T

53 lines
1.6 KiB
TypeScript

import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import fs from 'fs';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Nạp các biến môi trường từ thư mục gốc
const env = loadEnv(mode, path.resolve(__dirname, '..'), '');
// Cấu hình HTTPS nếu tìm thấy file chứng chỉ (ví dụ đặt tại thư mục gốc của dự án)
const httpsConfig = fs.existsSync('../key.pem') && fs.existsSync('../cert.pem')
? {
key: fs.readFileSync('../key.pem'),
cert: fs.readFileSync('../cert.pem'),
}
: undefined;
return {
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
port: 3002,
host: true,
// Cho phép các host từ file .env
allowedHosts: env.ALLOWED_HOSTS ? env.ALLOWED_HOSTS.split(',') : true,
https: httpsConfig,
proxy: {
'/api': {
target: env.VITE_BACKEND_URL || 'http://localhost:3001',
changeOrigin: true,
},
'/uploads': {
target: env.VITE_BACKEND_URL || 'http://localhost:3001',
changeOrigin: true,
},
'/socket.io': {
target: env.VITE_BACKEND_URL || 'http://localhost:3001',
ws: true,
changeOrigin: true,
},
},
headers: {
'Cross-Origin-Opener-Policy': 'same-origin-allow-popups',
'Cross-Origin-Embedder-Policy': 'unsafe-none',
},
},
};
});