Move UI configs to DB

This commit is contained in:
Shweelan Samson authored and Zaid Abdulla committed 2019-01-16 05:22:14 -08:00
1 parent 192ed6b034
commit 1cceba3f8b
22 files changed
+337 -448

No files matched your search

+19 -9
View File
@@ -4,7 +4,7 @@ const http = require("http");
const https = require("https");
const url = require("url");
const config = require("./config");
const config = require("../config");
const db = require("./db");
const mongodbFunctions = require("./mongodb-functions");
@@ -71,7 +71,9 @@ function deleteResource(resource, id) {
const resourceUrl =
resource === "virtualParameters" ? "virtual_parameters" : resource;
const options = url.parse(
`${config.server.nbi}${resourceUrl}/${encodeURIComponent(id)}`
`http://127.0.0.1:${config.get(
"NBI_PORT"
)}/${resourceUrl}/${encodeURIComponent(id)}`
);
options.method = "DELETE";
@@ -91,9 +93,9 @@ function deleteResource(resource, id) {
function postTask(task, connectionRequest, callback) {
const options = url.parse(
`${config.server.nbi}devices/${encodeURIComponent(task.device)}/tasks${
connectionRequest ? "?connection_request" : ""
}`
`http://127.0.0.1:${config.get("NBI_PORT")}/devices/${encodeURIComponent(
task.device
)}/tasks${connectionRequest ? "?connection_request" : ""}`
);
options.method = "POST";
const _http = options.protocol === "https:" ? https : http;
@@ -210,7 +212,9 @@ function updateTags(deviceId, tags) {
([tag, onOff]) =>
new Promise((resolve, reject) => {
const options = url.parse(
`${config.server.nbi}devices/${encodeURIComponent(
`http://127.0.0.1:${config.get(
"NBI_PORT"
)}/devices/${encodeURIComponent(
deviceId
)}/tags/${encodeURIComponent(tag)}`
);
@@ -234,7 +238,9 @@ function updateTags(deviceId, tags) {
function ping(host) {
return new Promise((resolve, reject) => {
const options = url.parse(
`${config.server.nbi}ping/${encodeURIComponent(host)}`
`http://127.0.0.1:${config.get("NBI_PORT")}/ping/${encodeURIComponent(
host
)}`
);
const _http = options.protocol === "https:" ? https : http;
@@ -294,7 +300,9 @@ function putResource(resource, id, data) {
const resourceUrl =
resource === "virtualParameters" ? "virtual_parameters" : resource;
const options = url.parse(
`${config.server.nbi}${resourceUrl}/${encodeURIComponent(id)}`
`http://127.0.0.1:${config.get(
"NBI_PORT"
)}/${resourceUrl}/${encodeURIComponent(id)}`
);
options.method = "PUT";
@@ -343,7 +351,9 @@ function putResource(resource, id, data) {
function putFile(id, metadata, fileStream) {
return new Promise((resolve, reject) => {
const options = url.parse(
`${config.server.nbi}files/${encodeURIComponent(id)}`
`http://127.0.0.1:${config.get("NBI_PORT")}/files/${encodeURIComponent(
id
)}`
);
options.method = "PUT";