From 31585c4b6bf82bccb14521622b89b927b2189fc6 Mon Sep 17 00:00:00 2001 From: ztimson Date: Wed, 30 Oct 2024 11:05:21 -0400 Subject: [PATCH] Log server start --- src/daemon.js | 4 ++-- src/main.js | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/daemon.js b/src/daemon.js index ed1e1c3..f2a0833 100644 --- a/src/daemon.js +++ b/src/daemon.js @@ -14,9 +14,9 @@ export default class Daemon { this.express = express(); - this.express.use(cors('*')); + this.express.use(cors('*')); - this.express.get('/api/*', async (req, res) => { + this.express.get('/api/*', async (req, res) => { const cmd = req.params['0']; res.json(await this.run(cmd)); }); diff --git a/src/main.js b/src/main.js index 716e4fe..82f035f 100644 --- a/src/main.js +++ b/src/main.js @@ -30,8 +30,11 @@ function run(cmd) { else if(cmd.startsWith('remote')) { remote = cmd.split(' ').pop(); return `Remote Set: ${remote}`; - } else if(cmd.startsWith('start')) new Daemon(+cmd.split(' ').pop() || 1969); - else return fetch(`${remote.startsWith('http') ? '' : 'http://'}${remote}/api/${cmd}`).then(resp => { + } else if(cmd.startsWith('start')) { + const port = +cmd.split(' ').pop() || 1969; + new Daemon(port); + return `Listening on: http://localhost:${port}`; + } else return fetch(`${remote.startsWith('http') ? '' : 'http://'}${remote}/api/${cmd}`).then(resp => { if(resp.ok && resp.headers['Content-Type']?.includes('json')) return resp.json(); else return resp.text(); @@ -41,7 +44,7 @@ function run(cmd) { } } -if(command) console.log(run(command)); +if(command) return console.log(run(command)); else console.log(help()); while(true) { const cmd = await ask('> ');