From b661e5511f2dfa2e7a479b75bbe608eb632f69c1 Mon Sep 17 00:00:00 2001 From: Kalam Azad Date: Tue, 12 Mar 2024 13:25:53 +0800 Subject: [PATCH] Add Restarting --- index.js | 12 ++++++++++-- restclient/test.http | 10 +++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 7998744..58eba2a 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ const express = require('express'); const multer = require('multer'); - +const { exec } = require('child_process'); const path = require('path'); const {checkKeyMatch,checkFileMatch} = require("./lib/validation") const bodyParser = require('body-parser'); @@ -159,7 +159,15 @@ function startServer(port) { fs.watch(jsonPath, (event, filename) => { if (event === 'change') { console.log('Endpoints file changed. Restarting server...'); - startServer(port); + + exec('pm2 restart engine', (error, stdout, stderr) => { + if (error) { + console.error(`Error restarting application: ${error}`); + return; + } + console.log(`Application restarted: ${stdout}`); + startServer(port); + }); } }); diff --git a/restclient/test.http b/restclient/test.http index 1f707a4..e75575d 100644 --- a/restclient/test.http +++ b/restclient/test.http @@ -1,4 +1,5 @@ -@HOST = http://localhost:3000 +@HOST = http://lhdn.kollect.biz:3000 +@LOCAL = http://localhost:3000 ### POST {{HOST}}/api/v1/student @@ -91,4 +92,11 @@ Content-Type: application/json GET {{HOST}}/api/v1/getlhdn +Content-Type: application/json + + +### + + +GET {{LOCAL}}/api/v1/getlhdn6 Content-Type: application/json \ No newline at end of file