AyumuUeha | 76a01bc | 2017-05-18 13:34:13 +0900 | [diff] [blame^] | 1 | /**
|
| 2 | * NetcfgConsolidator - Contains PPPoE device report functions
|
| 3 | */
|
| 4 | var jsonServer = require('json-server')
|
| 5 | var server = jsonServer.create()
|
| 6 | var router = jsonServer.router('db.json')
|
| 7 | var middlewares = jsonServer.defaults()
|
| 8 | var fs=require('fs');
|
| 9 | var __dirname = "/usr/local/lib/node_modules"
|
| 10 | var sendOper = require(__dirname + '/addAndDeleteApList')
|
| 11 | // Set default middlewares (logger, static, cors and no-cache)
|
| 12 | server.use(middlewares)
|
| 13 |
|
| 14 | server.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 | })
|
| 32 | server.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 |
|
| 47 | server.use(router)
|
| 48 | server.listen(24000, function () {
|
| 49 | console.log('NETCFG-Consolidator Server is running')
|
| 50 | })
|