From 81e6acb29b084ac840c67fe5c5b3d88206f2fc98 Mon Sep 17 00:00:00 2001 From: Molunerfinn Date: Wed, 1 Jan 2020 00:06:48 +0800 Subject: [PATCH] :bug: Fix: handle empty request-body --- src/main/server/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/server/index.ts b/src/main/server/index.ts index de55c752..6afeb989 100644 --- a/src/main/server/index.ts +++ b/src/main/server/index.ts @@ -29,7 +29,7 @@ class Server { }) request.on('end', () => { try { - postObj = JSON.parse(body) + postObj = (body === '') ? {} : JSON.parse(body) } catch (err) { return handleResponse({ response, @@ -53,7 +53,7 @@ class Server { } private listen = (port: number) => { console.log(`server listen at ${port}`) - this.httpServer.listen(port).on('error', (err: ErrnoException) => { + this.httpServer.listen(port, '0.0.0.0').on('error', (err: ErrnoException) => { if (err.errno === 'EADDRINUSE') { console.log(`----- Port ${port} is busy, trying with port ${port + 1} -----`) this.port += 1