feat: add base64 endpoint
This commit is contained in:
@@ -5,6 +5,7 @@ const PORT = process.env.PORT || 3000
|
|||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
if (req.url === '/') return respondHello(req, res)
|
if (req.url === '/') return respondHello(req, res)
|
||||||
if (req.url === '/user-agent') return respondUserAgent(req, res)
|
if (req.url === '/user-agent') return respondUserAgent(req, res)
|
||||||
|
if (req.url.match(/^\/b64\//)) return respondBase64(req, res)
|
||||||
|
|
||||||
res.end()
|
res.end()
|
||||||
})
|
})
|
||||||
@@ -18,6 +19,11 @@ function respondUserAgent (req, res) {
|
|||||||
res.end(JSON.stringify({ ua }))
|
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)
|
server.listen(PORT)
|
||||||
console.log(`Server listening on port ${PORT}`)
|
console.log(`Server listening on port ${PORT}`)
|
||||||
|
|
||||||
|
|||||||
9
test.js
9
test.js
@@ -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) {
|
tape('cleanup', function (t) {
|
||||||
server.close()
|
server.close()
|
||||||
t.end()
|
t.end()
|
||||||
|
|||||||
Reference in New Issue
Block a user