Matteo Scandolo | aca8665 | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
AyumuUeha | 76a01bc | 2017-05-18 13:34:13 +0900 | [diff] [blame] | 19 | /**
|
| 20 | * NetcfgConsolidator - Contains PPPoE device report functions
|
| 21 | */
|
| 22 | var jsonServer = require('json-server')
|
| 23 | var server = jsonServer.create()
|
| 24 | var router = jsonServer.router('db.json')
|
| 25 | var middlewares = jsonServer.defaults()
|
| 26 | var fs=require('fs');
|
| 27 | var __dirname = "/usr/local/lib/node_modules"
|
| 28 | var sendOper = require(__dirname + '/addAndDeleteApList')
|
| 29 | // Set default middlewares (logger, static, cors and no-cache)
|
| 30 | server.use(middlewares)
|
| 31 |
|
| 32 | server.post('/:device',function(req,res){
|
| 33 | console.log("device:"+req.params.device);
|
| 34 | var device = req.params.device;
|
| 35 | var str = device.split(":");
|
| 36 | console.log("str:"+str);
|
| 37 | console.log("enter post");
|
| 38 | console.log("port:"+str[2]);
|
| 39 | var netcfgDbObj = {};
|
| 40 | var testjson = {"ip":str[1],"port":parseInt(str[2]),"protocol": "http"};
|
| 41 | netcfgDbObj = JSON.parse(fs.readFileSync(__dirname + '/netconfigdb.json'));
|
| 42 | console.log(JSON.stringify(netcfgDbObj));
|
| 43 | var resProm = sendOper.addApList(netcfgDbObj,testjson,device);
|
| 44 | console.log(resProm);
|
| 45 | var data = {"state":"Add data success."};
|
| 46 | res.jsonp(data)
|
| 47 |
|
| 48 |
|
| 49 | })
|
| 50 | server.delete('/:device',function(req,res){
|
| 51 | var device = req.params.device;
|
| 52 | console.log("device:"+device);
|
| 53 | var str = device.split(":");
|
| 54 | console.log("enter delte");
|
| 55 | var netcfgDbObj = {};
|
| 56 | var testjson = {"ip":str[1],"port":str[2],"protocol": "http"};
|
| 57 | console.log(testjson);
|
| 58 | netcfgDbObj = JSON.parse(fs.readFileSync(__dirname + '/netconfigdb.json'));
|
| 59 | var resProm = sendOper.deleteApList(netcfgDbObj,testjson,device);
|
| 60 | console.log(resProm);
|
| 61 | var data = {"state":"Delete data success."}
|
| 62 | res.jsonp(data)
|
| 63 | })
|
| 64 |
|
| 65 | server.use(router)
|
| 66 | server.listen(24000, function () {
|
| 67 | console.log('NETCFG-Consolidator Server is running')
|
| 68 | })
|