2019-09-24 03:18:35 +00:00
|
|
|
'use strict'
|
|
|
|
const express = require('express')
|
|
|
|
const router = express.Router()
|
|
|
|
const pub = require('../pub')
|
|
|
|
|
|
|
|
router.get('/:name', function (req, res) {
|
2019-10-12 18:30:33 +00:00
|
|
|
const id = req.params.name
|
|
|
|
if (!id) {
|
2019-09-24 03:18:35 +00:00
|
|
|
return res.status(400).send('Bad request.')
|
|
|
|
} else {
|
2019-10-12 18:30:33 +00:00
|
|
|
// TODO: don't attempt to resolve remote ids if request is cross-origin
|
|
|
|
// (to prevent abuse of guppe server to DDoS other servers)
|
|
|
|
pub.object.resolve(id)
|
2019-09-24 03:18:35 +00:00
|
|
|
.then(obj => {
|
|
|
|
if (obj) {
|
|
|
|
return res.json(pub.utils.toJSONLD(obj))
|
|
|
|
}
|
|
|
|
return res.status(404).send('Object not found')
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2019-10-01 01:55:20 +00:00
|
|
|
console.log(err.message)
|
2019-09-24 03:18:35 +00:00
|
|
|
res.status(500).send()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = router
|