sailkick-boat 0.22.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cloud/index.js +16 -0
- package/lib/profile/index.js +19 -3
- package/package.json +1 -1
package/lib/cloud/index.js
CHANGED
|
@@ -164,7 +164,23 @@ function createCloud (app, options = {}) {
|
|
|
164
164
|
res.end(JSON.stringify(obj))
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
// Signal K mounts plugin routers AFTER its own bodyParser.json(), so on that path the
|
|
168
|
+
// body is already parsed and the request stream is spent — listening for 'data'/'end'
|
|
169
|
+
// waits for events that will never fire, and the request hangs for ever with no error.
|
|
170
|
+
// (That is exactly what happened: the Sync page sat on "Signing in…".) On the mirror
|
|
171
|
+
// there is no body parser and the stream is live, so both paths must be handled.
|
|
167
172
|
function readJson (req) {
|
|
173
|
+
if (req.body !== undefined && req.body !== null) {
|
|
174
|
+
if (typeof req.body === 'string') {
|
|
175
|
+
if (!req.body.trim()) return Promise.resolve(null)
|
|
176
|
+
try { return Promise.resolve(JSON.parse(req.body)) } catch { return Promise.resolve(undefined) }
|
|
177
|
+
}
|
|
178
|
+
if (typeof req.body === 'object') {
|
|
179
|
+
// bodyParser.json() gives {} for an absent body; treat that as "nothing sent".
|
|
180
|
+
return Promise.resolve(Object.keys(req.body).length || Array.isArray(req.body) ? req.body : null)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (req.readableEnded || req.complete) return Promise.resolve(null) // stream already drained
|
|
168
184
|
return new Promise((resolve) => {
|
|
169
185
|
let size = 0
|
|
170
186
|
const chunks = []
|
package/lib/profile/index.js
CHANGED
|
@@ -84,16 +84,32 @@ function createProfile (app, options = {}) {
|
|
|
84
84
|
const badBody = (res, what) => send(res, 400, { ok: false, code: 'bad-body', message: `${what} must be a JSON object` })
|
|
85
85
|
const failed = (res, e) => { lastError = e.message; warn(e.message); send(res, 500, { ok: false, code: 'profile-error', message: e.message }) }
|
|
86
86
|
|
|
87
|
+
// Signal K mounts plugin routers AFTER its own bodyParser.json(), so on that path the
|
|
88
|
+
// body is already parsed and the request stream is spent — listening for 'data'/'end'
|
|
89
|
+
// waits for events that will never fire, and the request hangs for ever with no error.
|
|
90
|
+
// (That is exactly what happened: the Sync page sat on "Signing in…".) On the mirror
|
|
91
|
+
// there is no body parser and the stream is live, so both paths must be handled.
|
|
87
92
|
function readJson (req) {
|
|
88
|
-
|
|
93
|
+
if (req.body !== undefined && req.body !== null) {
|
|
94
|
+
if (typeof req.body === 'string') {
|
|
95
|
+
if (!req.body.trim()) return Promise.resolve(null)
|
|
96
|
+
try { return Promise.resolve(JSON.parse(req.body)) } catch { return Promise.resolve(undefined) }
|
|
97
|
+
}
|
|
98
|
+
if (typeof req.body === 'object') {
|
|
99
|
+
// bodyParser.json() gives {} for an absent body; treat that as "nothing sent".
|
|
100
|
+
return Promise.resolve(Object.keys(req.body).length || Array.isArray(req.body) ? req.body : null)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (req.readableEnded || req.complete) return Promise.resolve(null) // stream already drained
|
|
104
|
+
return new Promise((resolve) => {
|
|
89
105
|
let size = 0
|
|
90
106
|
const chunks = []
|
|
91
107
|
req.on('data', (c) => {
|
|
92
108
|
size += c.length
|
|
93
|
-
if (size > MAX_BODY_BYTES) {
|
|
109
|
+
if (size > MAX_BODY_BYTES) { req.destroy(); resolve(undefined); return }
|
|
94
110
|
chunks.push(c)
|
|
95
111
|
})
|
|
96
|
-
req.on('error',
|
|
112
|
+
req.on('error', () => resolve(undefined))
|
|
97
113
|
req.on('end', () => {
|
|
98
114
|
const raw = Buffer.concat(chunks).toString('utf8')
|
|
99
115
|
if (!raw.trim()) return resolve(null)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sailkick-boat",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"description": "Run the sailkick app on board with no internet: charts, weather, climatology, trends and AIS all served from the boat itself. With a sailkick account it also syncs your metrics to the cloud in real time. Alpha, invite-only \u2014 info@sailkick.io",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|