Skip to content

Commit f996440

Browse files
committed
better metadata for upring-control
1 parent f1c73a0 commit f996440

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

bin.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const querystring = require('querystring')
99
const Transform = require('readable-stream').Transform
1010
const pino = require('pino-http')
1111
const pump = require('pump')
12+
const urlFormatLax = require('url-format-lax')
1213
const args = require('minimist')(process.argv.slice(2), {
1314
boolean: ['help', 'verbose'],
1415
default: {
@@ -72,7 +73,20 @@ db.upring.on('up', function () {
7273
throw err
7374
}
7475

75-
console.log('server listening on', server.address())
76+
const address = server.address()
77+
78+
if (address.address === '::') {
79+
address.host = '::1'
80+
} else {
81+
address.host = address.address
82+
}
83+
84+
const url = 'http://' + urlFormatLax(address)
85+
86+
// expose the address
87+
db.upring.info.url = url
88+
89+
console.log('server listening on', url)
7690
})
7791

7892
function handleGet (req, res) {
@@ -127,8 +141,12 @@ db.upring.on('up', function () {
127141
})
128142

129143
req.on('end', function () {
144+
var contentType = req.headers['content-type']
145+
if (!contentType || contentType === 'application/x-www-form-urlencoded') {
146+
contentType = 'text/plain'
147+
}
130148
db.put(req.url, {
131-
contentType: req.headers['content-type'],
149+
contentType,
132150
value: str
133151
}, function (err) {
134152
if (err) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"pino-http": "^1.3.0",
4646
"pump": "^1.0.1",
4747
"readable-stream": "^2.1.5",
48-
"upring": "^0.13.0"
48+
"upring": "^0.13.0",
49+
"url-format-lax": "^1.0.0"
4950
}
5051
}

0 commit comments

Comments
 (0)