-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
44 lines (37 loc) · 967 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
const Hapi = require('@hapi/hapi')
const { resolve: resolveStacksDid } = require('@stacks/did-resolver')
const init = async () => {
const server = Hapi.server({
port: 8080,
host: '0.0.0.0'
})
server.route({
method: 'GET',
path: '/identifiers/{identifier}',
handler: async (request, h) => {
const did = request.params['identifier']
let resp
try {
resp = h.response(await resolveStacksDid(did))
resp.code(200)
} catch (err) {
resp = h.response({ error: err.message })
resp.code(400)
console.error(`failed to resolve ${did}`, err)
}
return resp
}
})
await server.start()
console.log('Server running on %s', server.info.uri)
}
process.on('unhandledRejection', (err) => {
console.error('unhandled rejection!', err)
process.exit(1)
})
process.on('SIGINT', () => {
console.log('Received SIGINT. Quitting.')
process.exit(0)
})
init()