Explorar o código

Add self-describing response for /

jmacura %!s(int64=4) %!d(string=hai) anos
pai
achega
8d2acc307b
Modificáronse 2 ficheiros con 22 adicións e 1 borrados
  1. 21 0
      helpers.js
  2. 1 1
      index.js

+ 21 - 0
helpers.js

@@ -3,6 +3,27 @@
 */
 const fs = require('fs');
 
+module.exports.describeSelf = function (req, res) {
+  const description = {
+    description: 'Rural attractiveness web service',
+    methods: {
+      GET: [
+        '/refresh',
+        '/:aoi?/datasets/',
+        '/:aoi?/scores/:nuts',
+        '/:aoi?/scores',
+        '/:aoi?/runR/',
+        '/georeport/:nuts'
+      ],
+      POST: [
+        '/:aoi?/scores',
+        '/:aoi?/clusters/'
+      ]
+    }
+  }
+  this.formatResponse(description, req, res)
+}
+
 module.exports.formatResponse = function (obj, req, res) {
     res.header("Content-Type", 'application/json');
 

+ 1 - 1
index.js

@@ -33,7 +33,7 @@ app.set('view engine', 'pug')
 
 /* Dummy web service call without the method specified */
 app.get('/', (req, res) => {
-  res.send('Rural attractivness web service');
+  helpers.describeSelf(req, res)
 });
 
 /* Makes refresh of the data loaded to the server objects.