Added basic rest api

This commit is contained in:
vjrj 2018-04-12 10:45:20 +02:00
parent 903375a102
commit 8dc1ec63f2
5 changed files with 79 additions and 2 deletions

View file

@ -65,3 +65,4 @@ nspangler:autoreconnect
saucecode:timezoned-synced-cron
meteorhacks:kadira
meteorhacks:zones
nimble:restivus

View file

@ -92,6 +92,7 @@ mongo-id@1.0.6
mongo-livedata@1.0.12
mys:fonts@0.0.2
natestrauser:publish-performant-counts@0.1.2
nimble:restivus@0.8.12
npm-bcrypt@0.9.3
npm-mongo@2.2.34
nspangler:autoreconnect@0.0.1
@ -126,6 +127,7 @@ service-configuration@1.0.11
session@1.1.7
sha@1.0.9
shell-server@0.3.0
simple:json-routes@2.1.0
spacebars@1.0.15
spacebars-compiler@1.1.3
srp@1.0.10

View file

@ -27,4 +27,8 @@ Feature: Test all secundary pages
Given a list of non visible pages ids and contents
| status | Status |
| error | Upps |
# FIXME: find a way to monitor json pages
# | api/v1/status/last-fire-detected | updateAt |
# | api/v1/status/last-fire-check | description |
# | api/v1/status/active-fires-count | total |
Then I check that all non visible pages works properly

View file

@ -16,3 +16,4 @@ import './feedback';
import './cron';
import './isMaster';
import './segfaults';
import './rest';

View file

@ -0,0 +1,69 @@
/* global Restivus */
/* eslint-disable import/no-absolute-path */
import { Meteor } from 'meteor/meteor';
import Fires from '/imports/api/Fires/Fires';
import SiteSettings from '/imports/api/SiteSettings/SiteSettings';
import ActiveFiresCollection from '/imports/api/ActiveFires/ActiveFires';
Meteor.startup(() => {
const apiV1 = new Restivus({
useDefaultAuth: true,
apiPath: 'api',
version: 'v1',
prettyJson: true
});
// Generates: POST on /api/users and GET, DELETE /api/users/:id for
// Meteor.users collection
/* apiV1.addCollection(Meteor.users, {
* excludedEndpoints: ['getAll', 'put'],
* routeOptions: {
* authRequired: true
* },
* endpoints: {
* post: {
* authRequired: false
* },
* delete: {
* roleRequired: 'admin'
* }
* }
* }); */
apiV1.addCollection(Fires, {
excludedEndpoints: ['put', 'post', 'patch', 'delete'],
// excludedEndpoints: ['getAll', 'put', 'post', 'patch', 'delete'],
routeOptions: {
authRequired: false
},
endpoints: {
get: {
action: function getFire() {
return Fires.findOne(new Meteor.Collection.ObjectID(this.urlParams.id));
}
}
}
});
// Maps to: /api/v1/status/last-fire-check
apiV1.addRoute('status/last-fire-check', { authRequired: false }, {
get: function get() {
return SiteSettings.findOne({ name: 'last-fire-check' });
}
});
// Maps to: /api/v1/status/last-fire-detected
apiV1.addRoute('status/last-fire-detected', { authRequired: false }, {
get: function get() {
return ActiveFiresCollection.findOne({}, { sort: { when: -1 } });
}
});
// Maps to: /api/v1/status/last-fire-detected
apiV1.addRoute('status/active-fires-count', { authRequired: false }, {
get: function get() {
return { total: ActiveFiresCollection.find({}).count() };
}
});
});