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 https = require('https');
const express = require('express');
const bodyParser = require('body-parser')
// const request = require('ajax-request');
// const request = require('request');
const axios = require('axios');
const fs = require('fs');
const express = require('express')
const app = express();
const bodyParser = require('body-parser')
const soap = require('soap');
app.use(bodyParser.urlencoded({ extended: false }))
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');
// Certificate
const privateKey = fs.readFileSync('/etc/letsencrypt/live/umfrage.smartvillages.online/privkey.pem', 'utf8');
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
};
const { isEmptyObject } = require('jquery');
//console.log(polycalc)
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 hoursDifference
var secondsDifference
var daysDifference
function timeDifference(date11,date22) {
var date2 = new Date(date11);
var date1 = new Date(date22);
......@@ -101,17 +81,18 @@ function timeDifference1(date11,date22) {
}
//===========================================================================================================================
//Final Version
//===========================================================================================================================
// ---- Traffic Flow ----
// - 3Parts -
// - 3Parts - 48.7823,9.1807,919
// - get request from the html page
app.get('/TrafficFlow', async (req, res) => {
console.log('command angekommen!')
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');
try{
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);
console.log(json_tf)
var json_tfs = {
......@@ -124,12 +105,12 @@ app.get('/TrafficFlow', async (req, res) => {
res.json(json_tfs)
}catch (error) {
}catch (error) {
console.log(error)
}
});
// - request from the here API
function flow_getApiResponse(url) {
}
});
// - request from the here API
function flow_getApiResponse(url) {
return new Promise(function (resolve, reject) {
axios.get(url)
.then(function (response) {
......@@ -143,9 +124,9 @@ app.get('/TrafficFlow', async (req, res) => {
reject(error);
});
});
}
// - build geojson from response
function flow_buildTFLOWJson(inputData){
}
// - build geojson from response
function flow_buildTFLOWJson(inputData){
return new Promise(function (resolve, reject) {
try {
var json_tflow = inputData
......@@ -317,15 +298,15 @@ app.get('/TrafficFlow', async (req, res) => {
});
};
};
// ---- Accidents ----
// - 3Parts -
// - get request from the html page
app.get('/CONSTRUCTION', async (req, res) => {
// ---- Accidents ----
// - 3Parts -
// - get request from the html page
app.get('/CONSTRUCTION', async (req, res) => {
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 json_con = await CON_buildTFLOWJson(APIout,"CONSTRUCTION");
......@@ -338,14 +319,14 @@ app.get('/TrafficFlow', async (req, res) => {
};
res.json(json_cons)
}catch (error) {
}catch (error) {
console.log(error)
}
}
});
app.get('/ROAD_CLOSURE', async (req, res) => {
});
app.get('/ROAD_CLOSURE', async (req, res) => {
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 json_con = await CON_buildTFLOWJson(APIout,"ROAD_CLOSURE");
......@@ -358,13 +339,13 @@ app.get('/TrafficFlow', async (req, res) => {
};
res.json(json_cons)
}catch (error) {
}catch (error) {
console.log(error)
}
}
});
// - request from the here API
function CON_getApiResponse(url) {
});
// - request from the here API
function CON_getApiResponse(url) {
return new Promise(function (resolve, reject) {
console.log(url)
axios.get(url)
......@@ -379,9 +360,9 @@ app.get('/TrafficFlow', async (req, res) => {
reject(error);
});
});
}
// - build geojson from response
function CON_buildTFLOWJson(inputData,type){
}
// - build geojson from response
function CON_buildTFLOWJson(inputData,type){
return new Promise(function (resolve, reject) {
try {
var JsonFeature = [];
......@@ -453,14 +434,16 @@ app.get('/TrafficFlow', async (req, res) => {
});
};
};
// ---- Navpoint ----
// - receive coordinates and return a geojson
app.get('/addPoint', async (req, res) => {
// ---- Navpoint ----
// - receive coordinates and return a geojson
app.get('/addPoint', async (req, res) => {
try {
var data = req.query;
console.log(data)
var Punktadd = {
"type":"FeatureCollection",
"name":"data_point",
......@@ -494,12 +477,12 @@ app.get('/TrafficFlow', async (req, res) => {
console.log(error)
}
});
});
// http://localhost:8083/Routecalc2?slat=48.68997020356071&slon=9.202611390575258&sloc=Start&elat=48.726559406813294&elon=9.113775973868089&eloc=End
// ---- Route Berechnen Test ----
app.get('/Routecalc2', async (req, res) => {
// http://localhost:8083/Routecalc2?slat=48.68997020356071&slon=9.202611390575258&sloc=Start&elat=48.726559406813294&elon=9.113775973868089&eloc=End
// ---- Route Berechnen Test ----
app.get('/Routecalc2', async (req, res) => {
console.log('command angekommen ////// Route/////!')
const pointData = req.query;
console.log(pointData);
......@@ -524,9 +507,9 @@ app.get('/TrafficFlow', async (req, res) => {
console.log('.../loadSetP failed!\n' + err);
}
});
// - build geojson for Car Routing
function Route_buildJson(inputData){
});
// - build geojson for Car Routing
function Route_buildJson(inputData){
return new Promise(function (resolve, reject) {
try {
var JsonFeature = [];
......@@ -650,9 +633,9 @@ app.get('/TrafficFlow', async (req, res) => {
});
};
// ---- Route Offis Berechnen Test ----
app.get('/navPublicT2', async (req, res) => {
};
// ---- Route Offis Berechnen Test ----
app.get('/navPublicT2', async (req, res) => {
console.log('command angekommen ////// Route/////!')
const pointData = req.query;
console.log(pointData);
......@@ -684,10 +667,10 @@ app.get('/TrafficFlow', async (req, res) => {
console.log('.../loadSetP failed!\n' + err);
}
});
});
// - build geojson for Public Routing
function Route_PublicbuildJson(inputData){
// - build geojson for Public Routing
function Route_PublicbuildJson(inputData){
return new Promise(function (resolve, reject) {
try {
var JsonFeature = [];
......@@ -802,14 +785,15 @@ app.get('/TrafficFlow', async (req, res) => {
});
};
};
// ---- Noise Real Time ----
// - 3Parts -
// - get request from the html page
app.get('/NoiseRealTime', async (req, res) => {
// ---- Noise Real Time ----
// - 3Parts -
// - get request from the html page
app.get('/NoiseRealTime', async (req, res) => {
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 + '/');
console.log(APIout);
......@@ -817,33 +801,33 @@ app.get('/TrafficFlow', async (req, res) => {
res.json((APIout));
}catch (error) {
}catch (error) {
console.log(error)
}
});
}
});
// ---- Historic Noise Data ----
// ---- Trial Version from PostgreSQL ----
const pgp = require('pg-promise')({
// ---- Historic Noise Data ----
// ---- Trial Version from PostgreSQL ----
const pgp = require('pg-promise')({
// Initialization Options
});
});
const connection = {
const connection = {
user: 'postgres', // name of the user account
database: 'NoiseSensorData', // name of the database
password: 'ahpk94meteor', // env var: PGPASSWORD
host: '193.196.38.112', // Server hosting the postgres database (host: '35.187.21.114')
database: 'NoiseSensorData', // name of the database -- NoiseSensorData
password: 'postgres', // env var: PGPASSWORD -- ahpk94meteor
host: 'localhost', // Server hosting the postgres database (host: '35.187.21.114') -- 193.196.38.112
port: 5432, // env var: PGPORT
max: 10, // max number of clients in the pool
idleTimeoutMillis: 30000 // how long a client is allowed to remain idle before being closed
}
}
const db = pgp(connection);
console.log('successful connected to DB: NoiseSensorData!')
const db = pgp(connection);
console.log('successful connected to DB: NoiseSensorData!')
app.post('/getNoiseHist', function (req, res) {
app.post('/getNoiseHist', function (req, res) {
try {
......@@ -868,9 +852,9 @@ app.get('/TrafficFlow', async (req, res) => {
catch (err) {
console.log('.../getNoiseHist failed!\n' + err);
}
});
});
app.post('/getSTANoiseHist', async (req, res) => {
app.post('/getSTANoiseHist', async (req, res) => {
console.log('command angekommen ////// STANoise/////!')
const pointData = req.query;
......@@ -910,10 +894,10 @@ app.get('/TrafficFlow', async (req, res) => {
catch (err) {
console.log('.../loadSetP failed!\n' + err);
}
});
});
function STA_getApiResponse(url) {
function STA_getApiResponse(url) {
return new Promise(function (resolve, reject) {
// console.log(url)
axios.get(url)
......@@ -928,9 +912,10 @@ app.get('/TrafficFlow', async (req, res) => {
reject(error);
});
});
}
}
const connectionFav = {
const connectionFav = {
user: 'postgres', // name of the user account
database: 'FavoritPlaces', // name of the database
......@@ -945,12 +930,14 @@ app.get('/TrafficFlow', async (req, res) => {
const dbFav = pgp(connectionFav);
console.log('successful connected to DB: FavoritPlaces!')
// ---- FavPlaces ----
// - 3Parts -
// - get request from the html page
app.get('/FavPlacesDB', async (req, res) => {
console.log('FavPlacesDB angekommen!')
try{
try{
let APIout = await getDBResult('');
console.log(APIout)
let json_con = await buildFavJson(APIout,"CONSTRUCTION");
......@@ -963,13 +950,13 @@ app.get('/FavPlacesDB', async (req, res) => {
};
res.json(json_cons)
}catch (error) {
}catch (error) {
console.log(error)
}
}
});
// - request from the here API
function getDBResult(url) {
});
// - request from the here API
function getDBResult(url) {
return new Promise(function (resolve, reject) {
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) => {
reject(error);
});
});
}
// - build geojson from response
function buildFavJson(inputData,type){
}
// - build geojson from response
function buildFavJson(inputData,type){
return new Promise(function (resolve, reject) {
try {
var JsonFeature = [];
......@@ -1034,9 +1021,9 @@ app.get('/FavPlacesDB', async (req, res) => {
});
};
};
app.post('/saveFavPoint', function (req, res) {
app.post('/saveFavPoint', function (req, res) {
try {
......@@ -1061,4 +1048,4 @@ app.get('/FavPlacesDB', async (req, res) => {
catch (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