-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (37 loc) · 1.18 KB
/
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
import { fastify } from "fastify"
import { Resolver } from 'did-resolver'
import { getResolver } from 'itn-did-resolver'
const server = fastify()
server.get("/1.0/identifiers/:did", async (req, res) => {
try {
// verify parameter
const { did } = req.params as { did: string }
if (!did) throw new Error(`[did] parameter is required.`)
// verify environment variable
const didResolverUrl = process.env.DID_RESOLVER_URL
if (!didResolverUrl) {
throw new Error(`DID_RESOLVER_URL env variable is not set.`)
}
// create DID Resolver
const itnResolver = getResolver(didResolverUrl)
const didResolver = new Resolver({
...itnResolver
})
// resolve DID
const result = await didResolver.resolve(did)
res.send(result)
} catch (e: unknown) {
console.error(e)
res.status(500)
res.send({ error: e instanceof Error ? e.message : e })
}
})
const port = process.env.PORT || "8080"
const url = await server.listen({
host: "0.0.0.0",
port: Number(port),
backlog: 100000,
})
console.log("==================================");
console.log(`DID Resolver is [${process.env.DID_RESOLVER_URL}]`)
console.log(`Listening at [${url}]`)