Commit d2264460 authored by Cholgrrr's avatar Cholgrrr
Browse files

change Server, because cert expired

parent 39dd3ec3
const fs = require('fs');
const http = require('http'); const http = require('http');
const https = require('https'); const fs = require('fs');
const express = require('express'); const express = require('express')
const bodyParser = require('body-parser')
// const request = require('ajax-request');
// const request = require('request');
const axios = require('axios');
const app = express(); const app = express();
const bodyParser = require('body-parser')
const soap = require('soap');
app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json()) app.use(bodyParser.json())
const request_ajax = require('ajax-request');
const request = require('request');
// const got = require('got');
const axios = require('axios');
const polycalc = require('./codepoly.js'); const polycalc = require('./codepoly.js');
// Certificate const { isEmptyObject } = require('jquery');
const privateKey = fs.readFileSync('/etc/letsencrypt/live/umfrage.smartvillages.online/privkey.pem', 'utf8'); //console.log(polycalc)
const certificate = fs.readFileSync('/etc/letsencrypt/live/umfrage.smartvillages.online/cert.pem', 'utf8');
const ca = fs.readFileSync('/etc/letsencrypt/live/umfrage.smartvillages.online/chain.pem', 'utf8');
const credentials = {
key: privateKey,
cert: certificate,
ca: ca
};
app.use(express.static('vcm')); app.use(express.static('vcm'));
app.listen(process.env.PORT || 8083);
console.log("on 8083");
// Starting both http & https servers
// const httpServer = http.createServer(app);
const httpsServer = https.createServer(credentials, app);
// httpServer.listen(8081, () => {
// console.log('HTTP Server running on port 80');
// });
httpsServer.listen(8083, () => {
console.log('HTTPS Server running on port 443');
});
var minutesDifference var minutesDifference
var hoursDifference var hoursDifference
var secondsDifference var secondsDifference
var daysDifference var daysDifference
function timeDifference(date11,date22) { function timeDifference(date11,date22) {
var date2 = new Date(date11); var date2 = new Date(date11);
var date1 = new Date(date22); var date1 = new Date(date22);
...@@ -101,17 +81,18 @@ function timeDifference1(date11,date22) { ...@@ -101,17 +81,18 @@ function timeDifference1(date11,date22) {
} }
//=========================================================================================================================== //===========================================================================================================================
//Final Version //Final Version
//=========================================================================================================================== //===========================================================================================================================
// ---- Traffic Flow ---- // ---- Traffic Flow ----
// - 3Parts - // - 3Parts - 48.7823,9.1807,919
// - get request from the html page // - get request from the html page
app.get('/TrafficFlow', async (req, res) => { app.get('/TrafficFlow', async (req, res) => {
console.log('command angekommen!') console.log('command angekommen!')
try{ try{
let APIout = await flow_getApiResponse('https://traffic.ls.hereapi.com/traffic/6.2/flow.json?prox=48.7823,9.1807,919&responseattributes=sh%2Cfc&apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y'); let APIout = await flow_getApiResponse('https://traffic.ls.hereapi.com/traffic/6.2/flow.json?prox=48.7544,9.1768,8745&responseattributes=sh%2Cfc&apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y');
console.log(APIout)
let json_tf = await flow_buildTFLOWJson(APIout); let json_tf = await flow_buildTFLOWJson(APIout);
console.log(json_tf) console.log(json_tf)
var json_tfs = { var json_tfs = {
...@@ -124,12 +105,12 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -124,12 +105,12 @@ app.get('/TrafficFlow', async (req, res) => {
res.json(json_tfs) res.json(json_tfs)
}catch (error) { }catch (error) {
console.log(error) console.log(error)
} }
}); });
// - request from the here API // - request from the here API
function flow_getApiResponse(url) { function flow_getApiResponse(url) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
axios.get(url) axios.get(url)
.then(function (response) { .then(function (response) {
...@@ -143,9 +124,9 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -143,9 +124,9 @@ app.get('/TrafficFlow', async (req, res) => {
reject(error); reject(error);
}); });
}); });
} }
// - build geojson from response // - build geojson from response
function flow_buildTFLOWJson(inputData){ function flow_buildTFLOWJson(inputData){
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
try { try {
var json_tflow = inputData var json_tflow = inputData
...@@ -317,15 +298,15 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -317,15 +298,15 @@ app.get('/TrafficFlow', async (req, res) => {
}); });
}; };
// ---- Accidents ---- // ---- Accidents ----
// - 3Parts - // - 3Parts -
// - get request from the html page // - get request from the html page
app.get('/CONSTRUCTION', async (req, res) => { app.get('/CONSTRUCTION', async (req, res) => {
console.log('Construction angekommen!') console.log('Construction angekommen!')
try{ try{
let APIout = await CON_getApiResponse('https://traffic.ls.hereapi.com/traffic/6.3/incidents.json?apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y&bbox=48.790,9.139;48.771,9.239'); let APIout = await CON_getApiResponse('https://traffic.ls.hereapi.com/traffic/6.3/incidents.json?apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y&bbox=48.790,9.139;48.771,9.239');
let json_con = await CON_buildTFLOWJson(APIout,"CONSTRUCTION"); let json_con = await CON_buildTFLOWJson(APIout,"CONSTRUCTION");
...@@ -338,14 +319,14 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -338,14 +319,14 @@ app.get('/TrafficFlow', async (req, res) => {
}; };
res.json(json_cons) res.json(json_cons)
}catch (error) { }catch (error) {
console.log(error) console.log(error)
} }
}); });
app.get('/ROAD_CLOSURE', async (req, res) => { app.get('/ROAD_CLOSURE', async (req, res) => {
console.log('Construction angekommen!') console.log('Construction angekommen!')
try{ try{
let APIout = await CON_getApiResponse('https://traffic.ls.hereapi.com/traffic/6.3/incidents.json?apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y&bbox=48.790,9.139;48.771,9.239'); let APIout = await CON_getApiResponse('https://traffic.ls.hereapi.com/traffic/6.3/incidents.json?apiKey=9Grm-6B7VRvxAnbf2eKw29gR-9uuJP8VaXXYR8LK93Y&bbox=48.790,9.139;48.771,9.239');
let json_con = await CON_buildTFLOWJson(APIout,"ROAD_CLOSURE"); let json_con = await CON_buildTFLOWJson(APIout,"ROAD_CLOSURE");
...@@ -358,13 +339,13 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -358,13 +339,13 @@ app.get('/TrafficFlow', async (req, res) => {
}; };
res.json(json_cons) res.json(json_cons)
}catch (error) { }catch (error) {
console.log(error) console.log(error)
} }
}); });
// - request from the here API // - request from the here API
function CON_getApiResponse(url) { function CON_getApiResponse(url) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
console.log(url) console.log(url)
axios.get(url) axios.get(url)
...@@ -379,9 +360,9 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -379,9 +360,9 @@ app.get('/TrafficFlow', async (req, res) => {
reject(error); reject(error);
}); });
}); });
} }
// - build geojson from response // - build geojson from response
function CON_buildTFLOWJson(inputData,type){ function CON_buildTFLOWJson(inputData,type){
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
try { try {
var JsonFeature = []; var JsonFeature = [];
...@@ -453,14 +434,16 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -453,14 +434,16 @@ app.get('/TrafficFlow', async (req, res) => {
}); });
}; };
// ---- Navpoint ---- // ---- Navpoint ----
// - receive coordinates and return a geojson // - receive coordinates and return a geojson
app.get('/addPoint', async (req, res) => { app.get('/addPoint', async (req, res) => {
try { try {
var data = req.query; var data = req.query;
console.log(data)
var Punktadd = { var Punktadd = {
"type":"FeatureCollection", "type":"FeatureCollection",
"name":"data_point", "name":"data_point",
...@@ -494,12 +477,12 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -494,12 +477,12 @@ app.get('/TrafficFlow', async (req, res) => {
console.log(error) console.log(error)
} }
}); });
// http://localhost:8083/Routecalc2?slat=48.68997020356071&slon=9.202611390575258&sloc=Start&elat=48.726559406813294&elon=9.113775973868089&eloc=End // http://localhost:8083/Routecalc2?slat=48.68997020356071&slon=9.202611390575258&sloc=Start&elat=48.726559406813294&elon=9.113775973868089&eloc=End
// ---- Route Berechnen Test ---- // ---- Route Berechnen Test ----
app.get('/Routecalc2', async (req, res) => { app.get('/Routecalc2', async (req, res) => {
console.log('command angekommen ////// Route/////!') console.log('command angekommen ////// Route/////!')
const pointData = req.query; const pointData = req.query;
console.log(pointData); console.log(pointData);
...@@ -524,9 +507,9 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -524,9 +507,9 @@ app.get('/TrafficFlow', async (req, res) => {
console.log('.../loadSetP failed!\n' + err); console.log('.../loadSetP failed!\n' + err);
} }
}); });
// - build geojson for Car Routing // - build geojson for Car Routing
function Route_buildJson(inputData){ function Route_buildJson(inputData){
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
try { try {
var JsonFeature = []; var JsonFeature = [];
...@@ -650,9 +633,9 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -650,9 +633,9 @@ app.get('/TrafficFlow', async (req, res) => {
}); });
}; };
// ---- Route Offis Berechnen Test ---- // ---- Route Offis Berechnen Test ----
app.get('/navPublicT2', async (req, res) => { app.get('/navPublicT2', async (req, res) => {
console.log('command angekommen ////// Route/////!') console.log('command angekommen ////// Route/////!')
const pointData = req.query; const pointData = req.query;
console.log(pointData); console.log(pointData);
...@@ -684,10 +667,10 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -684,10 +667,10 @@ app.get('/TrafficFlow', async (req, res) => {
console.log('.../loadSetP failed!\n' + err); console.log('.../loadSetP failed!\n' + err);
} }
}); });
// - build geojson for Public Routing // - build geojson for Public Routing
function Route_PublicbuildJson(inputData){ function Route_PublicbuildJson(inputData){
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
try { try {
var JsonFeature = []; var JsonFeature = [];
...@@ -802,14 +785,15 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -802,14 +785,15 @@ app.get('/TrafficFlow', async (req, res) => {
}); });
}; };
// ---- Noise Real Time ---- // ---- Noise Real Time ----
// - 3Parts - // - 3Parts -
// - get request from the html page // - get request from the html page
app.get('/NoiseRealTime', async (req, res) => { app.get('/NoiseRealTime', async (req, res) => {
console.log('command angekommen!') console.log('command angekommen!')
try{ try{
console.log('https://data.sensor.community/airrohr/v1/sensor/' + req.query.id + '/')
let APIout = await flow_getApiResponse('https://data.sensor.community/airrohr/v1/sensor/' + req.query.id + '/'); let APIout = await flow_getApiResponse('https://data.sensor.community/airrohr/v1/sensor/' + req.query.id + '/');
console.log(APIout); console.log(APIout);
...@@ -817,33 +801,33 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -817,33 +801,33 @@ app.get('/TrafficFlow', async (req, res) => {
res.json((APIout)); res.json((APIout));
}catch (error) { }catch (error) {
console.log(error) console.log(error)
} }
}); });
// ---- Historic Noise Data ---- // ---- Historic Noise Data ----
// ---- Trial Version from PostgreSQL ---- // ---- Trial Version from PostgreSQL ----
const pgp = require('pg-promise')({ const pgp = require('pg-promise')({
// Initialization Options // Initialization Options
}); });
const connection = { const connection = {
user: 'postgres', // name of the user account user: 'postgres', // name of the user account
database: 'NoiseSensorData', // name of the database database: 'NoiseSensorData', // name of the database -- NoiseSensorData
password: 'ahpk94meteor', // env var: PGPASSWORD password: 'postgres', // env var: PGPASSWORD -- ahpk94meteor
host: '193.196.38.112', // Server hosting the postgres database (host: '35.187.21.114') host: 'localhost', // Server hosting the postgres database (host: '35.187.21.114') -- 193.196.38.112
port: 5432, // env var: PGPORT port: 5432, // env var: PGPORT
max: 10, // max number of clients in the pool max: 10, // max number of clients in the pool
idleTimeoutMillis: 30000 // how long a client is allowed to remain idle before being closed idleTimeoutMillis: 30000 // how long a client is allowed to remain idle before being closed
} }
const db = pgp(connection); const db = pgp(connection);
console.log('successful connected to DB: NoiseSensorData!') console.log('successful connected to DB: NoiseSensorData!')
app.post('/getNoiseHist', function (req, res) { app.post('/getNoiseHist', function (req, res) {
try { try {
...@@ -868,9 +852,9 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -868,9 +852,9 @@ app.get('/TrafficFlow', async (req, res) => {
catch (err) { catch (err) {
console.log('.../getNoiseHist failed!\n' + err); console.log('.../getNoiseHist failed!\n' + err);
} }
}); });
app.post('/getSTANoiseHist', async (req, res) => { app.post('/getSTANoiseHist', async (req, res) => {
console.log('command angekommen ////// STANoise/////!') console.log('command angekommen ////// STANoise/////!')
const pointData = req.query; const pointData = req.query;
...@@ -910,10 +894,10 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -910,10 +894,10 @@ app.get('/TrafficFlow', async (req, res) => {
catch (err) { catch (err) {
console.log('.../loadSetP failed!\n' + err); console.log('.../loadSetP failed!\n' + err);
} }
}); });
function STA_getApiResponse(url) { function STA_getApiResponse(url) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
// console.log(url) // console.log(url)
axios.get(url) axios.get(url)
...@@ -928,9 +912,10 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -928,9 +912,10 @@ app.get('/TrafficFlow', async (req, res) => {
reject(error); reject(error);
}); });
}); });
} }
const connectionFav = { const connectionFav = {
user: 'postgres', // name of the user account user: 'postgres', // name of the user account
database: 'FavoritPlaces', // name of the database database: 'FavoritPlaces', // name of the database
...@@ -945,12 +930,14 @@ app.get('/TrafficFlow', async (req, res) => { ...@@ -945,12 +930,14 @@ app.get('/TrafficFlow', async (req, res) => {
const dbFav = pgp(connectionFav); const dbFav = pgp(connectionFav);
console.log('successful connected to DB: FavoritPlaces!') console.log('successful connected to DB: FavoritPlaces!')
// ---- FavPlaces ---- // ---- FavPlaces ----
// - 3Parts - // - 3Parts -
// - get request from the html page // - get request from the html page
app.get('/FavPlacesDB', async (req, res) => { app.get('/FavPlacesDB', async (req, res) => {
console.log('FavPlacesDB angekommen!') console.log('FavPlacesDB angekommen!')
try{ try{
let APIout = await getDBResult(''); let APIout = await getDBResult('');
console.log(APIout) console.log(APIout)
let json_con = await buildFavJson(APIout,"CONSTRUCTION"); let json_con = await buildFavJson(APIout,"CONSTRUCTION");
...@@ -963,13 +950,13 @@ app.get('/FavPlacesDB', async (req, res) => { ...@@ -963,13 +950,13 @@ app.get('/FavPlacesDB', async (req, res) => {
}; };
res.json(json_cons) res.json(json_cons)
}catch (error) { }catch (error) {
console.log(error) console.log(error)
} }
}); });
// - request from the here API // - request from the here API
function getDBResult(url) { function getDBResult(url) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
let query_string = " SELECT id, lat, lon, contenttext, approved, timestamp FROM public.places WHERE approved = true;" let query_string = " SELECT id, lat, lon, contenttext, approved, timestamp FROM public.places WHERE approved = true;"
...@@ -989,9 +976,9 @@ app.get('/FavPlacesDB', async (req, res) => { ...@@ -989,9 +976,9 @@ app.get('/FavPlacesDB', async (req, res) => {
reject(error); reject(error);
}); });
}); });
} }
// - build geojson from response // - build geojson from response
function buildFavJson(inputData,type){ function buildFavJson(inputData,type){
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
try { try {
var JsonFeature = []; var JsonFeature = [];
...@@ -1034,9 +1021,9 @@ app.get('/FavPlacesDB', async (req, res) => { ...@@ -1034,9 +1021,9 @@ app.get('/FavPlacesDB', async (req, res) => {
}); });
}; };
app.post('/saveFavPoint', function (req, res) { app.post('/saveFavPoint', function (req, res) {
try { try {
...@@ -1061,4 +1048,4 @@ app.get('/FavPlacesDB', async (req, res) => { ...@@ -1061,4 +1048,4 @@ app.get('/FavPlacesDB', async (req, res) => {
catch (err) { catch (err) {
console.log('.../saveFavPoint failed!\n' + err); console.log('.../saveFavPoint failed!\n' + err);
} }
}); });
\ No newline at end of file \ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment