rubberguppe/routes/object.js
2019-09-30 20:55:20 -05:00

26 lines
638 B
JavaScript

'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 => {
console.log(err.message)
res.status(500).send()
})
}
})
module.exports = router