From 2636531f6490a7e9fce680c94c5027abe10363ac Mon Sep 17 00:00:00 2001
From: codecolorist
Date: Tue, 7 Aug 2018 19:42:41 +0800
Subject: [PATCH] now you can display syslog
---
app.js | 39 +++++++++++++++++-----------------
bin/cli.js | 32 +++++++++++++++++++++++++++-
gui/src/views/Inspect.vue | 3 +++
gui/src/views/tabs/Console.vue | 6 +++++-
gui/src/vuex/mods/console.js | 5 +++++
gui/src/vuex/types.js | 3 +++
lib/config.js | 4 ++++
lib/rpc.js | 12 ++++++-----
scripts/dev-all.js | 2 +-
9 files changed, 78 insertions(+), 28 deletions(-)
create mode 100644 lib/config.js
diff --git a/app.js b/app.js
index c234249..a83e58c 100644
--- a/app.js
+++ b/app.js
@@ -54,10 +54,6 @@ router
ctx.body = { status: 'ok', pid }
})
-const port = parseInt(process.env.PORT, 10) || 31337
-const host = process.env.HOST || 'localhost'
-
-
app
.use(compress({
filter(contentType) {
@@ -97,21 +93,24 @@ if (process.env.NODE_ENV === 'development') {
app.use(logger())
}
-console.info(`listening on http://${host}:${port}`.green)
-const server = http.createServer(app.callback())
-channels.attach(server)
-server.listen(port, host)
-
-
-process.on('unhandledRejection', (err) => {
- console.error('An unhandledRejection occurred: ')
- console.error(`Rejection: ${err}`)
- console.error(err.stack)
-
- channels.broadcast('unhandledRejection', {
- err: err.toString(),
- stack: err.stack,
+function start({ host, port }) {
+ console.info(`listening on http://${host}:${port}`.green)
+ const server = http.createServer(app.callback())
+ channels.attach(server)
+ server.listen(port, host)
+ process.on('unhandledRejection', (err) => {
+ console.error('An unhandledRejection occurred: '.red)
+ console.error(`Rejection: ${err}`.red)
+ console.error(err.stack)
+
+ channels.broadcast('unhandledRejection', {
+ err: err.toString(),
+ stack: err.stack,
+ })
})
-})
+}
-module.exports = app
+module.exports = {
+ app,
+ start,
+}
diff --git a/bin/cli.js b/bin/cli.js
index e02eb4a..91874c8 100755
--- a/bin/cli.js
+++ b/bin/cli.js
@@ -1,3 +1,33 @@
#!/usr/bin/env node
+const net = require('net')
-require('../app.js')
+const app = require('../app')
+const config = require('../lib/config')
+
+function usage() {
+ console.log('usage: passionfruit {server|syslog}')
+ process.exit(-1)
+}
+
+function syslog() {
+ const port = parseInt(process.argv[3], 10)
+ if (Number.isNaN(port))
+ console.log('usage: passionfruit console [port]')
+
+ net.connect({ host: 'localhost', port })
+ .on('end', () => process.exit(0))
+ .pipe(process.stdout)
+}
+
+function main() {
+ if (process.argv.length > 2) {
+ const action = process.argv[2].toLowerCase()
+ if (action === 'syslog')
+ return syslog()
+ if (action !== 'server')
+ return usage()
+ }
+ return app.start(config)
+}
+
+main()
diff --git a/gui/src/views/Inspect.vue b/gui/src/views/Inspect.vue
index 0895260..1f6abb6 100644
--- a/gui/src/views/Inspect.vue
+++ b/gui/src/views/Inspect.vue
@@ -135,6 +135,7 @@ import { mapGetters, mapActions, mapMutations } from 'vuex'
import { AsyncSearch, debounce } from '~/lib/utils'
import {
GET_SOCKET, STORE_SOCKET,
+ STORE_SYSLOG_SERVER_PORT,
CONSOLE_UNREAD, CONSOLE_APPEND, CONSOLE_CLEAR,
DOWNLOADING, PROGRESS,
ALL_HOOKS, DELETE_HOOK,
@@ -202,6 +203,7 @@ export default {
this.$toast.open(`an exception has occured: ${err}`)
}
})
+ .on('syslog-port', this.setSyslogServerPort)
.on('console', this.consoleAppend)
.on('app', ({ app, device }) => {
this.device = device
@@ -241,6 +243,7 @@ export default {
}),
...mapMutations({
storeSocket: STORE_SOCKET,
+ setSyslogServerPort: STORE_SYSLOG_SERVER_PORT,
consoleAppend: CONSOLE_APPEND,
consoleClear: CONSOLE_CLEAR,
})
diff --git a/gui/src/views/tabs/Console.vue b/gui/src/views/tabs/Console.vue
index 7bccf02..49746f8 100644
--- a/gui/src/views/tabs/Console.vue
+++ b/gui/src/views/tabs/Console.vue
@@ -10,6 +10,9 @@
Clear
+ Use
+ nc localhost {{ port }}
or
+ passionfruit syslog {{ port }}
in terminal to view NSLog