blob: 4a44d455e67e2dbdaf51d0b51e3058a61ed7940e [file] [log] [blame]
Matteo Scandoloaca86652017-08-08 13:05:27 -07001
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
AyumuUeha76a01bc2017-05-18 13:34:13 +090019/**
20 * NetcfgConsolidator - Contains PPPoE device report functions
21 */
22var jsonServer = require('json-server')
23var server = jsonServer.create()
24var router = jsonServer.router('db.json')
25var middlewares = jsonServer.defaults()
26var fs=require('fs');
27var __dirname = "/usr/local/lib/node_modules"
28var sendOper = require(__dirname + '/addAndDeleteApList')
29// Set default middlewares (logger, static, cors and no-cache)
30server.use(middlewares)
31
32server.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})
50server.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
65server.use(router)
66server.listen(24000, function () {
67 console.log('NETCFG-Consolidator Server is running')
68})