forked from Mirrors/keyoxide-web
feat: Add graphql proxy endpoint
This commit is contained in:
parent
8a311f5dc6
commit
eadf5c14c3
1 changed files with 22 additions and 0 deletions
|
@ -277,4 +277,26 @@ router.get(
|
|||
}
|
||||
)
|
||||
|
||||
// GraphQL route
|
||||
router.get(
|
||||
'/graphql',
|
||||
query('url').isURL(),
|
||||
query('query').isString(),
|
||||
async (req, res) => {
|
||||
const errors = validationResult(req)
|
||||
if (!errors.isEmpty()) {
|
||||
return res.status(400).json({ errors: errors.array() })
|
||||
}
|
||||
|
||||
fetcher.graphql
|
||||
.fn(req.query, opts)
|
||||
.then((data) => {
|
||||
return res.status(200).send(data)
|
||||
})
|
||||
.catch((err) => {
|
||||
return res.status(400).json({ errors: err.message ? err.message : err })
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
export default router
|
||||
|
|
Loading…
Reference in a new issue