Files
cultivation-world-simulator/web/vite.config.ts
Zihao Xu bd6f7e67d5 feat(server): make server host and port configurable (#127)
* feat(server): make server host and port configurable

Support configuring server binding address via environment variables
and config files. Priority: ENV > local_config.yml > config.yml > default.

- Add host and port options to system section in config.yml
- Read SERVER_HOST and SERVER_PORT from environment variables
- Default to 127.0.0.1:8002 for security

Set host to "0.0.0.0" to allow LAN access.

* test(server): add comprehensive tests for server binding config

Add 28 test cases covering:
- Environment variable priority (SERVER_HOST, SERVER_PORT)
- Config file reading (system.host, system.port)
- Default value fallback
- OmegaConf integration
- Edge cases (IPv6, empty values, invalid ports)

* docs: add mobile/LAN access instructions

- Add mobile access section to README and EN_README
- Configure Vite to listen on 0.0.0.0 for LAN access in dev mode
- Link to Issue #130 for mobile UI compatibility tracking
2026-02-04 21:47:17 +08:00

48 lines
1.1 KiB
TypeScript

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { compilerOptions } from 'vue3-pixi'
import path from 'path'
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd())
const API_TARGET = env.VITE_API_TARGET || 'http://localhost:8002'
const WS_TARGET = env.VITE_WS_TARGET || 'ws://localhost:8002'
return {
plugins: [
vue({
template: {
compilerOptions,
},
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
},
build: {
assetsDir: 'web_static', // 避免与游戏原本的 /assets 目录冲突
},
server: {
host: '0.0.0.0', // 允许局域网访问
proxy: {
'/api': {
target: API_TARGET,
changeOrigin: true,
},
'/ws': {
target: WS_TARGET,
ws: true,
changeOrigin: true,
},
'/assets': {
target: API_TARGET,
changeOrigin: true,
}
}
}
}
})