2019-09-24 03:18:35 +00:00
|
|
|
'use strict'
|
|
|
|
const express = require('express')
|
|
|
|
const router = express.Router()
|
|
|
|
const store = require('../store')
|
|
|
|
const pub = require('../pub')
|
|
|
|
|
|
|
|
router.get('/:name', function (req, res) {
|
|
|
|
const name = req.params.name
|
|
|
|
if (!name) {
|
|
|
|
return res.status(400).send('Bad request.')
|
|
|
|
} else {
|
|
|
|
store.object.get(pub.utils.objectIdToIRI(name))
|
|
|
|
.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
|