diff --git a/.meteor/packages b/.meteor/packages index f49fd6a..3b71493 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -65,3 +65,4 @@ nspangler:autoreconnect saucecode:timezoned-synced-cron meteorhacks:kadira meteorhacks:zones +nimble:restivus diff --git a/.meteor/versions b/.meteor/versions index c76cf8b..cab08e8 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -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 diff --git a/cucumber/features/pages.feature b/cucumber/features/pages.feature index 1c17a30..ac66526 100644 --- a/cucumber/features/pages.feature +++ b/cucumber/features/pages.feature @@ -25,6 +25,10 @@ Feature: Test all secundary pages Scenario: Check that other non visible pages work well Given a list of non visible pages ids and contents - | status | Status | - | error | Upps | + | 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 diff --git a/imports/startup/server/index.js b/imports/startup/server/index.js index cb0d461..018ccdd 100644 --- a/imports/startup/server/index.js +++ b/imports/startup/server/index.js @@ -16,3 +16,4 @@ import './feedback'; import './cron'; import './isMaster'; import './segfaults'; +import './rest'; diff --git a/imports/startup/server/rest.js b/imports/startup/server/rest.js new file mode 100644 index 0000000..da10be6 --- /dev/null +++ b/imports/startup/server/rest.js @@ -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() }; + } + }); +});