From 82c366e05b10d98df9e6549dacd6a28089c58cea Mon Sep 17 00:00:00 2001 From: sco Date: Tue, 16 Jun 2020 01:25:22 +0200 Subject: [PATCH] internet-check edit --- node.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/node.js b/node.js index ae1ac3e..22a5a5c 100644 --- a/node.js +++ b/node.js @@ -4,6 +4,7 @@ const util = require('util'); const fs = require('fs'); const path = require('path'); const os = require('os'); +const http = require("http"); const exec = util.promisify(require('child_process').exec); const readFileAsync = util.promisify(fs.readFile); @@ -61,18 +62,22 @@ app.get('/internetCheck', async (req, res) => { res.set({ 'Access-Control-Allow-Origin': '*' }); - const { stdout, stderr } = await exec('/media/hd/data/projects/icanhazip'); - res.send( - { - "id": "internet-check", - "data": stdout, - "stderr": stderr - } - ) + http.get('http://icanhazip.com', (httpRes) => { + httpRes.setEncoding('utf8'); + httpRes.on('data', (body) => { + res.send( + { + "id": "internet-check", + "data": body, + "stderr": "" + } + ) + }); +}); }); -app.get('/sysStatus', async (req, res) => { +app.get('/sysStatus', (req, res) => { res.set({ 'Access-Control-Allow-Origin': '*' });