Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. module.exports = function(Networkinfo) {
  4.   var express = require('express');
  5.   var SensorLogger = express();
  6.   var bodyParser = require('body-parser');
  7.  
  8.   SensorLogger.use(function(req, res, next) {
  9.     res.setHeader('Access-Control-Allow-Origin', '*');
  10.     res.setHeader('Access-Control-Allow-Methods', 'GET, POST', 'OPTIONS');
  11. // eslint-disable-next-line max-len
  12.     res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
  13.     next();
  14.   });
  15.   SensorLogger.use(bodyParser.json());
  16.  
  17.   SensorLogger.post('/NetworkInfos/logSensor', function(req, res) {
  18.     console.log(JSON.stringify(req.body));
  19.     res.setHeader('Content-Type', 'application/json');
  20.     var response =
  21.       {
  22.         data: 'OK',
  23.       };
  24.     // Networkinfo.deleteAll();
  25.     Networkinfo.create(req.body);
  26.     res.send(JSON.stringify(response));
  27.   });
  28.  
  29.   SensorLogger.listen(8080);
  30.  
  31.   Networkinfo.list = function(msg, cb) {
  32.     console.log(Networkinfo);
  33.     Networkinfo.find({limit: msg, order: 'id DESC'}, function(err, data)    {
  34.       cb(null, data);
  35.     });
  36.   };
  37.  
  38.   Networkinfo.remoteMethod('list', {
  39.     accepts: {arg: 'quantity', type: 'string'},
  40.     returns: {arg: 'info', type: 'object'},
  41.     http: {path: '/list', verb: 'get'},
  42.   });
  43. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement