1
0
peddlers-of-ketran/client/vite.config.js

59 lines
2.0 KiB
JavaScript

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import fs from 'fs';
const httpsEnv = (process.env.HTTPS || '').toLowerCase();
const useHttps = httpsEnv === 'true' || httpsEnv === '1';
import tsconfigPaths from 'vite-tsconfig-paths'
// If custom cert paths are provided via env, use them; otherwise let Vite handle a self-signed cert when true.
const httpsOption = useHttps
? (process.env.VITE_HTTPS_KEY && process.env.VITE_HTTPS_CERT
? {
key: fs.readFileSync(process.env.VITE_HTTPS_KEY),
cert: fs.readFileSync(process.env.VITE_HTTPS_CERT)
}
: true)
: false;
export default defineConfig({
// Base public path when served in dev or production. Allow overriding
// via VITE_API_BASE (e.g. /ketr.ketran) so assets and manifest paths work.
base: '/',
plugins: [react(), tsconfigPaths()],
build: {
outDir: 'build',
},
server: {
host: process.env.HOST || '0.0.0.0',
port: Number(process.env.PORT) || 3001,
https: httpsOption,
proxy: {
// Support requests that already include the basePath (/ketr.ketran/api)
// and requests that use the shorter /api path. Both should be forwarded
// to the backend server which serves the API under /ketr.ketran/api.
'/ketr.ketran/api': {
target: 'http://peddlers-server:8930',
changeOrigin: true,
ws: true,
secure: false
},
'/api': {
target: 'http://peddlers-server:8930',
changeOrigin: true,
ws: true,
secure: false,
rewrite: (path) => `/ketr.ketran${path}`
}
},
// HMR options: advertise the external hostname and port so browsers
// accessing via `battle-linux.ketrenos.com` can connect to the websocket.
// The certs mounted into the container must be trusted by the browser.
hmr: {
host: process.env.VITE_HMR_HOST || 'battle-linux.ketrenos.com',
port: Number(process.env.VITE_HMR_PORT) || 3001,
protocol: process.env.VITE_HMR_PROTOCOL || 'wss'
},
}
});