feat: initial commit
This commit is contained in:
parent
3f6ccc0a15
commit
0c26994fd2
|
@ -0,0 +1,113 @@
|
|||
# Other
|
||||
*.csv
|
||||
.env~
|
||||
.env*
|
||||
f
|
||||
p
|
||||
*.tar.gz
|
||||
*.tgz
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and *not* Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
|
@ -0,0 +1,49 @@
|
|||
require('dotenv').config();
|
||||
const debug=require('debug')('debug');
|
||||
const helmet = require('helmet');
|
||||
const compression = require('compression');
|
||||
const express = require("express");
|
||||
const cors = require("cors");
|
||||
|
||||
//get API root with alive msg
|
||||
const rootRouter = require('./route/root');
|
||||
|
||||
const gtfsRtRouter = require('./route/gtfs-rt');
|
||||
|
||||
//TODO make this list available via config
|
||||
//limit access to this origin list
|
||||
let whitelist = [
|
||||
'http://localhost:8080',
|
||||
'http(s)://foo.bar'
|
||||
];
|
||||
|
||||
const app = express();
|
||||
|
||||
//compress all routes
|
||||
app.use(compression());
|
||||
|
||||
//protect against vulnerabilities
|
||||
app.use(helmet());
|
||||
|
||||
//configure cors
|
||||
app.use(cors({
|
||||
origin: function(origin, callback){
|
||||
// allow requests with no origin
|
||||
debug('origin: '+origin)
|
||||
if(!origin){
|
||||
return callback(null, true);
|
||||
}
|
||||
if(whitelist.indexOf(origin) === -1){
|
||||
let message = 'The cors policy for this origin does not allow access from the particular origin: '+origin;
|
||||
return callback(new Error(message), false);
|
||||
}
|
||||
debug('origin: '+origin+' allowed by cors');
|
||||
return callback(null, true);
|
||||
}
|
||||
}));
|
||||
|
||||
app.use('/', rootRouter);
|
||||
|
||||
app.use('/gtfs-rt',gtfsRtRouter);
|
||||
|
||||
module.exports=app;
|
|
@ -0,0 +1,36 @@
|
|||
const axios=require('axios');
|
||||
const debug=require('debug')('debug');
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const utils=require('../utils');
|
||||
|
||||
//GET listing
|
||||
router.get('/', async function(req, res, next) {
|
||||
debug('gtfs-rt start...');
|
||||
try {
|
||||
|
||||
const URL='http://gtfsr.vbn.de/gtfsr_connect.bin';
|
||||
const config = {
|
||||
responseType: 'arraybuffer'
|
||||
//responseType: 'blob'
|
||||
};
|
||||
|
||||
const rspns = await axios.get(URL,config);
|
||||
|
||||
const filename = 'gtfs-rt.bin';
|
||||
res.writeHead(200, {
|
||||
//'Content-Type': mimetype,
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-disposition': 'attachment;filename=' + filename,
|
||||
'Content-Length': rspns.data.length
|
||||
});
|
||||
res.end(Buffer.from(rspns.data, 'binary'));
|
||||
|
||||
} catch (err) {
|
||||
console.error(`Error: `, err.message);
|
||||
res.status(err.statusCode || 500).json(utils.MSGS.error);
|
||||
}
|
||||
debug('gtfs-rt done.');
|
||||
});
|
||||
module.exports = router;
|
|
@ -0,0 +1,12 @@
|
|||
const debug=require('debug')('debug');
|
||||
const expr = require('express');
|
||||
const router = expr.Router();
|
||||
const utils=require('../utils');
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/', function(req, res, next) {
|
||||
debug('root msg: '+utils.MSGS.alive);
|
||||
res.json(utils.MSGS.alive);
|
||||
});
|
||||
|
||||
module.exports = router;
|
|
@ -0,0 +1,11 @@
|
|||
const MSGS={
|
||||
'alive': 'alive',
|
||||
'done': 'done',
|
||||
'error': 'error',
|
||||
'errorPost': 'HTTP POST request body invalid',
|
||||
'duplicateGlobalIds': 'Duplicate Global Ids found.'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
MSGS
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
const DEBUG=require('debug')('index');
|
||||
const HTTPS = require('https');
|
||||
const FS = require('fs');
|
||||
|
||||
DEBUG('index start...');
|
||||
const APP=require('./app/app');
|
||||
|
||||
//TODO make port available via config
|
||||
//set port
|
||||
const PORT=parseInt(process.env.PORT, 10)||65535;
|
||||
DEBUG('PORT: '+PORT);
|
||||
|
||||
//TODO make env available via config
|
||||
//pass 'APP' to server
|
||||
DEBUG('NODE_ENV: '+process.env.NODE_ENV);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
DEBUG('development mode');
|
||||
APP.listen(PORT);
|
||||
}else{
|
||||
DEBUG('production mode');
|
||||
HTTPS.createServer({
|
||||
//TODO make key and cert available via config
|
||||
key: FS.readFileSync('./p'),
|
||||
cert: FS.readFileSync('./f')
|
||||
}, APP)
|
||||
.listen(PORT, ()=>DEBUG('listening on port '+PORT));
|
||||
}
|
||||
|
||||
DEBUG('index done.');
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"private": true,
|
||||
"name": "data-ui",
|
||||
"description": "API for VBN data",
|
||||
"version": "1.19.0",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"API",
|
||||
"VBN",
|
||||
"data"
|
||||
],
|
||||
"author": "Software Ingenieur Begerad <dialog@SwIngBe.de>",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nodemon index.js",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "1.4.0",
|
||||
"compression": "1.7.4",
|
||||
"cors": "2.8.5",
|
||||
"debug": "4.3.4",
|
||||
"dotenv": "16.3.1",
|
||||
"express": "4.18.2",
|
||||
"helmet": "7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "2.0.16"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"private": true,
|
||||
"name": "data-ui",
|
||||
"description": "API for VBN data",
|
||||
"version": "1.19.0",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"API",
|
||||
"VBN",
|
||||
"data"
|
||||
],
|
||||
"author": "Software Ingenieur Begerad <dialog@SwIngBe.de>",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nodemon index.js",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "1.4.0",
|
||||
"compression": "1.7.4",
|
||||
"cors": "2.8.5",
|
||||
"debug": "4.3.4",
|
||||
"dotenv": "16.0.1",
|
||||
"express": "4.18.1",
|
||||
"fs": "0.0.1-security",
|
||||
"gtfs-realtime-bindings": "1.1.1",
|
||||
"helmet": "5.1.0",
|
||||
"https": "1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "2.0.16"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue