-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from docknetwork/fix/api-routes-not-bundled
Add individual API proxy routes instead of bundled into one
- Loading branch information
Showing
24 changed files
with
335 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { dockUrl } from '../../utils/constants'; | ||
|
||
export default async (req, res) => { | ||
if (req.method !== 'POST') { | ||
console.log('Only post request allowed'); | ||
res.status(400).json({}); | ||
return; | ||
} | ||
|
||
let result; | ||
result = await fetch(`${dockUrl}/openid/issuers`, { | ||
method: 'POST', | ||
headers: { | ||
'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify(req.body), | ||
}); | ||
|
||
const response = await result.json(); | ||
if (!result.ok) { | ||
const errorText = await result.text(); | ||
throw new Error(`API Error: ${result.status} - ${errorText}`); | ||
} | ||
|
||
result = await fetch(`${dockUrl}/openid/credential-offers`, { | ||
method: 'POST', | ||
headers: { | ||
'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
id: response.id, | ||
}), | ||
}); | ||
|
||
const offerResponse = await result.json(); | ||
if (!result.ok) { | ||
const errorText = await result.text(); | ||
throw new Error(`API Error: ${result.status} - ${errorText}`); | ||
} | ||
|
||
res.status(202).send(offerResponse); | ||
}; |
12 changes: 4 additions & 8 deletions
12
pages/api/handle-credentials.js → pages/api/create-proof-request-object.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { generateNonce } from '../../utils/generate-nonce'; | ||
import { dockUrl } from '../../utils/constants'; | ||
|
||
export default async (req, res) => { | ||
if (req.method !== 'POST') { | ||
console.log('Only post request allowed'); | ||
res.status(400).json({}); | ||
return; | ||
} | ||
|
||
const result = await fetch(`${dockUrl}/proof-templates/${req.body.proofTemplateID}/request`, { | ||
method: 'POST', | ||
headers: { | ||
'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
nonce: `${generateNonce()}`, | ||
domain: 'dock.io', | ||
}), | ||
}); | ||
|
||
const response = await result.json(); | ||
if (!result.ok) { | ||
const errorText = await result.text(); | ||
throw new Error(`API Error: ${result.status} - ${errorText}`); | ||
} | ||
|
||
res.status(202).send(response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { dockUrl } from '../../utils/constants'; | ||
|
||
export default async (req, res) => { | ||
if (req.method !== 'POST') { | ||
console.log('Only post request allowed'); | ||
res.status(400).json({}); | ||
return; | ||
} | ||
|
||
const result = await fetch(`${dockUrl}/registries`, { | ||
method: 'POST', | ||
headers: { | ||
'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify(req.body), | ||
}); | ||
|
||
const response = await result.json(); | ||
if (!result.ok) { | ||
const errorText = await result.text(); | ||
throw new Error(`API Error: ${result.status} - ${errorText}`); | ||
} | ||
|
||
res.status(202).send(response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { dockUrl } from '../../utils/constants'; | ||
|
||
export default async (req, res) => { | ||
if (req.method !== 'GET') { | ||
console.log('Only GET request allowed'); | ||
res.status(400).json({}); | ||
return; | ||
} | ||
|
||
const result = await fetch( | ||
`${dockUrl}/registries?did=${encodeURIComponent(req.query.did)}&type=${encodeURIComponent(req.query.searchType)}`, | ||
{ | ||
method: 'GET', | ||
headers: { | ||
'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, | ||
'content-type': 'application/json', | ||
}, | ||
} | ||
); | ||
|
||
const response = await result.json(); | ||
|
||
if (!result.ok) { | ||
const errorText = await result.text(); | ||
throw new Error(`API get Error: ${result.status} - ${errorText}`); | ||
} | ||
|
||
res.status(202).send(response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { dockUrl } from '../../utils/constants'; | ||
|
||
export default async (req, res) => { | ||
if (req.method !== 'POST') { | ||
console.log('Only post request allowed'); | ||
res.status(400).json({}); | ||
return; | ||
} | ||
|
||
const result = await fetch(`${dockUrl}/openid/vp/${req.body.proofRequestId}/request-url`, { | ||
method: 'POST', | ||
headers: { | ||
'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
...req.body, | ||
proofRequestId: undefined, | ||
}), | ||
}); | ||
|
||
const response = await result.json(); | ||
if (!result.ok) { | ||
const errorText = await result.text(); | ||
throw new Error(`API Error: ${result.status} - ${errorText}`); | ||
} | ||
|
||
res.status(202).send(response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { dockUrl } from '../../utils/constants'; | ||
|
||
export default async (req, res) => { | ||
if (req.method !== 'POST') { | ||
console.log('Only post request allowed'); | ||
res.status(400).json({}); | ||
return; | ||
} | ||
|
||
const { issuer, type, subject, expirationDate } = req.body; | ||
|
||
const result = await fetch(`${dockUrl}/credentials`, { | ||
method: 'POST', | ||
headers: { | ||
'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
anchor: false, | ||
persist: false, | ||
credential: { | ||
name: type, | ||
type: ['VerifiableCredential', type], | ||
issuer, | ||
expirationDate, | ||
subject, | ||
}, | ||
algorithm: 'dockbbs+', | ||
}), | ||
}); | ||
|
||
const response = await result.json(); | ||
if (!result.ok) { | ||
const errorText = await result.text(); | ||
throw new Error(`API Error: ${result.status} - ${errorText}`); | ||
} | ||
|
||
res.status(202).send(response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { dockUrl } from '../../utils/constants'; | ||
|
||
export default async (req, res) => { | ||
if (req.method !== 'POST') { | ||
console.log('Only post request allowed'); | ||
res.status(400).json({}); | ||
return; | ||
} | ||
|
||
const result = await fetch(`${dockUrl}/credentials`, { | ||
method: 'POST', | ||
headers: { | ||
'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify(req.body), | ||
}); | ||
|
||
const response = await result.json(); | ||
if (!result.ok) { | ||
const errorText = await result.text(); | ||
throw new Error(`API Error: ${result.status} - ${errorText}`); | ||
} | ||
|
||
res.status(202).send(response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { dockUrl } from '../../utils/constants'; | ||
|
||
export default async (req, res) => { | ||
if (req.method !== 'POST') { | ||
console.log('Only post request allowed'); | ||
res.status(400).json({}); | ||
return; | ||
} | ||
|
||
const result = await fetch(`${dockUrl}/registries/${req.body.registryId}`, { | ||
method: 'POST', | ||
headers: { | ||
'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
...req.body, | ||
registryId: undefined, | ||
}), | ||
}); | ||
|
||
const response = await result.json(); | ||
if (!result.ok) { | ||
const errorText = await result.text(); | ||
throw new Error(`API Error: ${result.status} - ${errorText}`); | ||
} | ||
|
||
res.status(202).send(response); | ||
}; |
Oops, something went wrong.