Implement ENV Vars

This commit is contained in:
Fred Boniface 2022-12-19 22:26:51 +00:00
parent 9067079756
commit 52b1eda644
8 changed files with 35 additions and 88 deletions

12
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"problemMatcher": [],
"label": "npm: start",
"detail": "node app.js"
}
]
}

5
app.js
View File

@ -6,7 +6,6 @@
const express = require('express'); const express = require('express');
const app = express(); const app = express();
const config = require('./src/configs/server.configs');
const version = require('./src/configs/version.configs'); const version = require('./src/configs/version.configs');
const testRtr = require('./src/routes/test.routes'); const testRtr = require('./src/routes/test.routes');
const listRtr = require('./src/routes/list.routes'); const listRtr = require('./src/routes/list.routes');
@ -35,9 +34,9 @@ app.use('/api/v1/ldb', ldbRtr);
app.use('/api/kube', kubeRtr); app.use('/api/kube', kubeRtr);
// Start Express // Start Express
app.listen(config.port, config.listen, (error) =>{ app.listen(process.env.OWL_SRV_PORT, process.env.OWL_SRV_LISTEN, (error) =>{
if(!error) { if(!error) {
console.log(`Started server on http://${config.listen}:${config.port}`); console.log(`Started server on http://${process.env.OWL_SRV_LISTEN}:${process.env.OWL_SRV_PORT}`);
} else { } else {
console.log("Error occurred, server can't start", error); console.log("Error occurred, server can't start", error);
} }

View File

@ -1,54 +0,0 @@
function getUser(){
if (process.env.OWL_DB_USER){
var dbUser = process.env.OWL_DB_USER;
} else {
var dbUser = "ERR";
};
return dbUser;
}
function getPass(){
if (process.env.OWL_DB_PASS){
var dbPass = process.env.OWL_DB_USER;
} else {
var dbPass = "ERR";
};
return dbPass;
}
function getName(){
if (process.env.OWL_DB_NAME){
var dbName = process.env.OWL_DB_NAME;
} else {
var dbName = "owlboard";
};
return dbName;
}
function getPort(){
if (process.env.OWL_DB_PORT){
var dbPort = process.env.OWL_DB_PORT;
} else {
var dbPort = 3306
}
return Number(dbPort);
}
function getHost(){
if (process.env.OWL_DB_HOST){
var dbHost = process.env.OWL_DB_HOST;
} else {
var dbHost = "database";
}
return dbHost;
}
const database = {
user: getUser(),
password: getPass(),
database: getName(),
port: getPort(),
host: getHost()
};
module.exports = database;

View File

@ -1,28 +0,0 @@
function getPort(){
if (process.env.OWL_SRV_PORT){
var confPort = process.env.OWL_SRV_PORT;
} else {
var confPort = 8460;
};
return Number(confPort);
}
function getListen(){
if (process.env.OWL_SRV_LISTEN){
var confListen = process.env.OWL_SRV_LISTEN;
} else {
var confListen = "0.0.0.0"
}
return confListen;
}
const server = {
port: getPort(),
listen: getListen()
};
module.exports = {
server,
getPort,
getListen
}

View File

@ -1,7 +1,12 @@
const kube = require('../services/kube.services'); const kube = require('../services/kube.services');
async function getAlive(req, res, next){ async function getAlive(req, res, next){
res.status("200").send(`{"status":"alive"}`) try {
var state = kube.getAlive()
res.status((await state).code).send((await state).state)
} catch (err) {
res.status("503").send({state: "error"})
}
} }
async function getReady(req, res, next){ async function getReady(req, res, next){

View File

@ -1,7 +1,14 @@
// General DB Access aswell as dbInit tests etc. // General DB Access aswell as dbInit tests etc.
const database = require( '../utils/dbinit.utils' ) const database = require( '../utils/dbinit.utils' )
const options = require('../configs/database.confiigs')
const dbUser = process.env.OWL_DB_USER || "owl"
const dbPass = process.env.OWL_DB_PASS || ""
const dbName = process.env.OWL_DB_NAME || "owlboard"
const dbPort = process.env.OWL_DB_PORT || 0
const dbHost = process.env.OWL_DB_HOST || "database"
const { Client } = require( 'pg' ) const { Client } = require( 'pg' )

View File

@ -1,7 +1,12 @@
async function getAlive(){
return {code: 200, state: {state: "alive",noise: "twit-twoo"}}
}
async function getReady(){ async function getReady(){
return "not_implemented"; return "not_implemented";
}; };
module.exports = { module.exports = {
getAlive,
getReady getReady
} }

View File

@ -1,8 +1,9 @@
const version = require('../configs/version.configs'); const version = require('../configs/version.configs');
const corpus = require('../utils/corpus.utils');
async function get(){ async function get(){
// Databse lookup, get list of all stations as per the Python script output // Databse lookup, get list of all stations as per the Python script output
return {}; return corpus.init();
} }
module.exports = { module.exports = {