Log server start
This commit is contained in:
parent
1de19b208a
commit
31585c4b6b
@ -14,9 +14,9 @@ export default class Daemon {
|
|||||||
|
|
||||||
this.express = express();
|
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'];
|
const cmd = req.params['0'];
|
||||||
res.json(await this.run(cmd));
|
res.json(await this.run(cmd));
|
||||||
});
|
});
|
||||||
|
@ -30,8 +30,11 @@ function run(cmd) {
|
|||||||
else if(cmd.startsWith('remote')) {
|
else if(cmd.startsWith('remote')) {
|
||||||
remote = cmd.split(' ').pop();
|
remote = cmd.split(' ').pop();
|
||||||
return `Remote Set: ${remote}`;
|
return `Remote Set: ${remote}`;
|
||||||
} else if(cmd.startsWith('start')) new Daemon(+cmd.split(' ').pop() || 1969);
|
} else if(cmd.startsWith('start')) {
|
||||||
else return fetch(`${remote.startsWith('http') ? '' : 'http://'}${remote}/api/${cmd}`).then(resp => {
|
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'))
|
if(resp.ok && resp.headers['Content-Type']?.includes('json'))
|
||||||
return resp.json();
|
return resp.json();
|
||||||
else return resp.text();
|
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());
|
else console.log(help());
|
||||||
while(true) {
|
while(true) {
|
||||||
const cmd = await ask('> ');
|
const cmd = await ask('> ');
|
||||||
|
Loading…
Reference in New Issue
Block a user