1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/unleash-server/lib/api.js

38 lines
897 B
JavaScript
Raw Normal View History

var db = require('./db');
2014-10-20 15:12:30 +02:00
module.exports = function (app) {
2014-10-20 15:12:30 +02:00
app.get('/features', function (req, res) {
db.getFeatures().then(function (features) {
res.json(features);
});
2014-10-20 15:12:30 +02:00
});
app.get('/features/:id', function (req, res) {
db.getFeature.then(function (feature) {
if (feature) {
res.json(feature);
} else {
res.json(404, {error: 'Could not find feature'});
}
});
2014-10-20 15:12:30 +02:00
});
app.post('/features', function (req, res) {
var newFeature = req.body;
db.getFeature(newFeature.name).then(function (feature) {
if (feature) {
res.status(500).end();
} else {
db.addFeature(newFeature).then(function () {
res.status(201).end();
});
}
});
});
2014-10-20 15:12:30 +02:00
};