fix(web): change port to 3007, add auto port cleanup, graceful error handling

This commit is contained in:
2026-05-07 03:26:22 +08:00
parent 001dbde9f4
commit c257dd2b8c
6 changed files with 46 additions and 3 deletions

View File

@@ -13,9 +13,9 @@ export default defineConfig({
server: {
port: 5173,
proxy: {
'/api': 'http://localhost:3001',
'/api': 'http://localhost:3007',
'/ws': {
target: 'ws://localhost:3001',
target: 'ws://localhost:3007',
ws: true,
},
},

Binary file not shown.

Binary file not shown.

29
web/package-lock.json generated
View File

@@ -34,6 +34,7 @@
"@vitejs/plugin-react": "^4.3.0",
"autoprefixer": "^10.4.0",
"concurrently": "^9.1.0",
"kill-port": "^2.0.1",
"postcss": "^8.4.0",
"tailwindcss": "^3.4.0",
"tsx": "^4.19.0",
@@ -2677,6 +2678,13 @@
"node": ">= 0.4"
}
},
"node_modules/get-them-args": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/get-them-args/-/get-them-args-1.3.2.tgz",
"integrity": "sha512-LRn8Jlk+DwZE4GTlDbT3Hikd1wSHgLMme/+7ddlqKd7ldwR6LjJgTVWzBnR01wnYGe4KgrXjg287RaI22UHmAw==",
"dev": true,
"license": "MIT"
},
"node_modules/get-tsconfig": {
"version": "4.14.0",
"resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.14.0.tgz",
@@ -2955,6 +2963,20 @@
"node": ">=6"
}
},
"node_modules/kill-port": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/kill-port/-/kill-port-2.0.1.tgz",
"integrity": "sha512-e0SVOV5jFo0mx8r7bS29maVWp17qGqLBZ5ricNSajON6//kmb7qqqNnml4twNE8Dtj97UQD+gNFOaipS/q1zzQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"get-them-args": "1.3.2",
"shell-exec": "1.0.2"
},
"bin": {
"kill-port": "cli.js"
}
},
"node_modules/lilconfig": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.3.tgz",
@@ -3971,6 +3993,13 @@
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
"license": "ISC"
},
"node_modules/shell-exec": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/shell-exec/-/shell-exec-1.0.2.tgz",
"integrity": "sha512-jyVd+kU2X+mWKMmGhx4fpWbPsjvD53k9ivqetutVW/BQ+WIZoDoP4d8vUMGezV6saZsiNoW2f9GIhg9Dondohg==",
"dev": true,
"license": "MIT"
},
"node_modules/shell-quote": {
"version": "1.8.3",
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.3.tgz",

View File

@@ -4,6 +4,7 @@
"private": true,
"scripts": {
"dev": "concurrently \"npm run dev:server\" \"npm run dev:client\"",
"predev:server": "npx kill-port 3007",
"dev:server": "tsx watch server/index.ts",
"dev:client": "vite --config client/vite.config.ts",
"build": "vite build --config client/vite.config.ts",
@@ -36,6 +37,7 @@
"@vitejs/plugin-react": "^4.3.0",
"autoprefixer": "^10.4.0",
"concurrently": "^9.1.0",
"kill-port": "^2.0.1",
"postcss": "^8.4.0",
"tailwindcss": "^3.4.0",
"tsx": "^4.19.0",

View File

@@ -25,8 +25,20 @@ app.use('/api/configs', configsRouter);
wss.on('connection', handleChat);
const PORT = 3001;
const PORT = 3007;
initDb();
server.on('error', (err: NodeJS.ErrnoException) => {
if (err.code === 'EADDRINUSE') {
console.error(`Port ${PORT} is in use. Run: npx kill-port ${PORT}`);
process.exit(1);
}
throw err;
});
server.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
process.on('SIGTERM', () => { server.close(); process.exit(0); });
process.on('SIGINT', () => { server.close(); process.exit(0); });