blob: 498575cc1d19ff28bca77e90ed1019fe9e211068 [file] [log] [blame]
AyumuUeha76a01bc2017-05-18 13:34:13 +09001/**
2 * NetcfgConsolidator - Contains PPPoE device report functions
3 */
4var jsonServer = require('json-server')
5var server = jsonServer.create()
6var router = jsonServer.router('db.json')
7var middlewares = jsonServer.defaults()
8var fs=require('fs');
9var __dirname = "/usr/local/lib/node_modules"
10var sendOper = require(__dirname + '/addAndDeleteApList')
11// Set default middlewares (logger, static, cors and no-cache)
12server.use(middlewares)
13
14server.post('/:device',function(req,res){
15 console.log("device:"+req.params.device);
16 var device = req.params.device;
17 var str = device.split(":");
18 console.log("str:"+str);
19 console.log("enter post");
20 console.log("port:"+str[2]);
21 var netcfgDbObj = {};
22 var testjson = {"ip":str[1],"port":parseInt(str[2]),"protocol": "http"};
23 netcfgDbObj = JSON.parse(fs.readFileSync(__dirname + '/netconfigdb.json'));
24 console.log(JSON.stringify(netcfgDbObj));
25 var resProm = sendOper.addApList(netcfgDbObj,testjson,device);
26 console.log(resProm);
27 var data = {"state":"Add data success."};
28 res.jsonp(data)
29
30
31})
32server.delete('/:device',function(req,res){
33 var device = req.params.device;
34 console.log("device:"+device);
35 var str = device.split(":");
36 console.log("enter delte");
37 var netcfgDbObj = {};
38 var testjson = {"ip":str[1],"port":str[2],"protocol": "http"};
39 console.log(testjson);
40 netcfgDbObj = JSON.parse(fs.readFileSync(__dirname + '/netconfigdb.json'));
41 var resProm = sendOper.deleteApList(netcfgDbObj,testjson,device);
42 console.log(resProm);
43 var data = {"state":"Delete data success."}
44 res.jsonp(data)
45})
46
47server.use(router)
48server.listen(24000, function () {
49 console.log('NETCFG-Consolidator Server is running')
50})