Files
travelplanning/frontend/vite.config.ts
T

44 lines
1.2 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: 'http://127.0.0.1:3001',
changeOrigin: true,
},
'/socket.io': {
target: 'http://127.0.0.1:3001',
ws: true,
},
},
},
};
});