Skip to content

Commit

Permalink
fix: use URI encoded host in web-did-doc-router (#384)
Browse files Browse the repository at this point in the history
Closes #383
  • Loading branch information
sk91 committed Mar 26, 2021
1 parent 9712db0 commit 37186d5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/remote-server/src/web-did-doc-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ export const WebDidDocRouter = (): Router => {
return didDoc
}

const getAliasForRequest = async (req: Request) => {
return encodeURIComponent(req.get('host') || req.hostname)
}

router.get(didDocEndpoint, async (req: RequestWithAgentDIDManager, res) => {
if (req.agent) {
try {
const serverIdentifier = await req.agent.didManagerGet({
did: 'did:web:' + req.hostname,
did: 'did:web:' + getAliasForRequest(req),
})
const didDoc = didDocForIdentifier(serverIdentifier)
res.json(didDoc)
Expand All @@ -51,7 +55,7 @@ export const WebDidDocRouter = (): Router => {
if (req.agent) {
try {
const identifier = await req.agent.didManagerGet({
did: 'did:web:' + req.hostname + ':' + req.params[0].replace('/', ':'),
did: 'did:web:' + getAliasForRequest(req) + ':' + req.params[0].replace('/', ':'),
})
const didDoc = didDocForIdentifier(identifier)
res.json(didDoc)
Expand Down

0 comments on commit 37186d5

Please sign in to comment.