Skip to content

Commit

Permalink
Merge e7fe501 into bae038a
Browse files Browse the repository at this point in the history
  • Loading branch information
tiaanduplessis authored Apr 25, 2017
2 parents bae038a + e7fe501 commit c3f9ea2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
const assert = require('assert')
const http = require('http')
const internalIp = require('internal-ip')

module.exports = summary

// log the server port and env
// (obj, fn) -> null
function summary (server, write) {
function summary (server, write, additional) {
assert.ok(server instanceof http.Server, /expected instance of server/)
write = write || defaultWrite
additional = additional || {}

return function () {
const address = server.address()
const host = address.address === '::' ? internalIp() : 'localhost'
const port = address.port
const url = 'http://localhost:' + port
const url = 'http://' + host + ':' + port
const env = process.env.NODE_ENV || 'undefined'

write({
write(Object.assign(additional, {
port: port,
env: env,
pid: process.pid,
url: url
})
}))
}
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"callback"
],
"license": "MIT",
"dependencies": {},
"dependencies": {
"internal-ip": "~1.2.0"
},
"devDependencies": {
"garnish": "^5.0.1",
"istanbul": "^0.3.5",
Expand Down
15 changes: 14 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('should catch incorrect input', function (t) {
test('should log console output', function (t) {
t.plan(2)
const server = http.createServer()
server.listen(null, function () {
server.listen(0, function () {
const sum = summary(server, function (msg) {
t.equal(typeof msg, 'object', 'message is an object')
})
Expand All @@ -20,3 +20,16 @@ test('should log console output', function (t) {
server.close()
})
})

test('should allow additional values', function (t) {
t.plan(2)
const server = http.createServer()
server.listen(0, function () {
const sum = summary(server, function (msg) {
t.equal(typeof msg['log-level'], 'string', 'log-level is a string')
}, {'log-level': 'info'})
sum()
t.pass('server called')
server.close()
})
})

0 comments on commit c3f9ea2

Please sign in to comment.