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('端口监听失败。'); + } }); - })(); + +