feat: add base64 endpoint

This commit is contained in:
David
2019-06-14 12:26:08 -07:00
committed by Rod Hale
parent 33e41571c2
commit 1fe38f7e2c
2 changed files with 15 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ const PORT = process.env.PORT || 3000
const server = http.createServer((req, res) => {
if (req.url === '/') return respondHello(req, res)
if (req.url === '/user-agent') return respondUserAgent(req, res)
if (req.url.match(/^\/b64\//)) return respondBase64(req, res)
res.end()
})
@@ -18,6 +19,11 @@ function respondUserAgent (req, res) {
res.end(JSON.stringify({ ua }))
}
function respondBase64 (req, res) {
const phrase = req.url.replace(/^\/b64\//, '')
res.end(JSON.stringify({ b64: Buffer.from(phrase).toString('base64') }))
}
server.listen(PORT)
console.log(`Server listening on port ${PORT}`)

View File

@@ -25,6 +25,15 @@ tape('should respond user-agent', (t) => {
})
})
tape('should respond b64', (t) => {
jsonist.get(`${urlBase}/b64/hello`, (err, body) => {
if (err) t.error(err)
t.equal(body.b64, 'aGVsbG8=')
t.end()
})
})
tape('cleanup', function (t) {
server.close()
t.end()