From 8176e9c0348155b13cab9f039b9bd7acbd86b14e Mon Sep 17 00:00:00 2001 From: Cheney Date: Mon, 19 Aug 2024 18:11:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8D=8F=E8=AE=AE=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/src/main.js b/backend/src/main.js index 69f4ef9..b45f94c 100644 --- a/backend/src/main.js +++ b/backend/src/main.js @@ -4,7 +4,6 @@ const ukey = require("./FakeUKey") const cors = require('cors'); const { killPortProcess } = require('kill-port-process'); - const app = express(); // const port = 3000; const port = 8090; @@ -47,18 +46,19 @@ app.post('/do', (req, res) => { (async () => { + // long running process running on a given port(s), e.g. a http-server + // takes a number, number[], string or string[] + // single port + await killPortProcess(8090); - try { - await killPortProcess(port); - } catch (e) { - - } - - - - app.listen(port, () => { + app.listen(port, "127.0.0.1", () => { console.log(`Server is running on port ${port}`); + }).on('error', (err) => { + if (err.code === 'ECONNREFUSED') { + console.log('端口监听失败。'); + } }); - })(); + +