Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
dancingCycle | 9fc43a1eb2 | |
dancingCycle | 74ceaf1a65 |
|
@ -8,13 +8,16 @@ const cors = require("cors");
|
|||
//get API root with alive msg
|
||||
const rootRouter = require('./route/root');
|
||||
|
||||
//get a GTFS Realtime feed using another URL as source
|
||||
const gtfsRtRouter = require('./route/gtfs-rt');
|
||||
|
||||
//get a GTFS Realtime feed using a file as source
|
||||
const gtfsRtFileRouter = require('./route/gtfs-rt-file');
|
||||
|
||||
//TODO make this list available via config
|
||||
//limit access to this origin list
|
||||
let whitelist = [
|
||||
'http://localhost:8080',
|
||||
'http(s)://foo.bar'
|
||||
'http://localhost:8080'
|
||||
];
|
||||
|
||||
const app = express();
|
||||
|
@ -46,4 +49,6 @@ app.use('/', rootRouter);
|
|||
|
||||
app.use('/gtfs-rt',gtfsRtRouter);
|
||||
|
||||
app.use('/gtfs-rt-file',gtfsRtFileRouter);
|
||||
|
||||
module.exports=app;
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
const fs = require('fs');
|
||||
const debug=require('debug')('gtfsr');
|
||||
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 file = process.env.FILE||'foo.bar';
|
||||
debug('gtfs-rt:get() file: ' + file );
|
||||
|
||||
|
||||
const buffer = fs.readFileSync(file);
|
||||
if(buffer instanceof Buffer){
|
||||
debug('gtfs-rt:get() buffer is instance of Buffer');
|
||||
debug('buffer.length: ' + buffer.length);
|
||||
}else{
|
||||
debug('gtfs-rt:get() buffer is NOT instance of Buffer');
|
||||
res.status(err.statusCode || 500).json(utils.MSGS.error);
|
||||
}
|
||||
|
||||
const DLOAD_FILE_NAME = process.env.DLOAD_FILE_NAME || 'blub.blub';
|
||||
debug('gtfs-rt:get() DLOAD_FILE_NAME: ' + DLOAD_FILE_NAME );
|
||||
|
||||
res.writeHead(200, {
|
||||
//'Content-Type': mimetype,
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-disposition': 'attachment;filename=' + DLOAD_FILE_NAME,
|
||||
'Content-Length': buffer.length
|
||||
});
|
||||
res.end(Buffer.from(buffer, 'binary'));
|
||||
|
||||
} catch (err) {
|
||||
console.error(`Error: `, err.message);
|
||||
res.status(err.statusCode || 500).json(utils.MSGS.error);
|
||||
}
|
||||
debug('gtfs-rt done.');
|
||||
});
|
||||
module.exports = router;
|
|
@ -1,5 +1,5 @@
|
|||
const axios=require('axios');
|
||||
const debug=require('debug')('gtfs-rt');
|
||||
const debug=require('debug')('gtfsr');
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
|
|
|
@ -8,4 +8,4 @@ const MSGS={
|
|||
|
||||
module.exports = {
|
||||
MSGS
|
||||
}
|
||||
};
|
||||
|
|
16
index.js
16
index.js
|
@ -1,27 +1,27 @@
|
|||
const DEBUG=require('debug')('index');
|
||||
const debug=require('debug')('index');
|
||||
const HTTPS = require('https');
|
||||
const FS = require('fs');
|
||||
|
||||
DEBUG('index start...');
|
||||
debug('index start...');
|
||||
const APP=require('./app/app');
|
||||
|
||||
//set port
|
||||
const PORT=parseInt(process.env.PORT, 10)||65535;
|
||||
DEBUG('index: PORT: ' + PORT);
|
||||
debug('index: PORT: ' + PORT);
|
||||
|
||||
//pass 'APP' to server
|
||||
DEBUG('index: NODE_ENV: ' + process.env.NODE_ENV);
|
||||
debug('index: NODE_ENV: ' + process.env.NODE_ENV);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
DEBUG('index: development mode');
|
||||
debug('index: development mode');
|
||||
APP.listen(PORT);
|
||||
}else{
|
||||
DEBUG('index: production mode');
|
||||
debug('index: production mode');
|
||||
HTTPS.createServer({
|
||||
//TODO make key and cert available via config
|
||||
key: FS.readFileSync('./p'),
|
||||
cert: FS.readFileSync('./f')
|
||||
}, APP)
|
||||
.listen(PORT, ()=>DEBUG('index: listening on port '+PORT));
|
||||
.listen(PORT, ()=>debug('index: listening on port '+PORT));
|
||||
}
|
||||
|
||||
DEBUG('index: index done.');
|
||||
debug('index: index done.');
|
||||
|
|
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
|
@ -2,7 +2,7 @@
|
|||
"private": true,
|
||||
"name": "gtfs-rt-proxy",
|
||||
"description": "GTFS Realtime Proxy",
|
||||
"version": "0.2.0",
|
||||
"version": "0.3.0",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"GTFS",
|
||||
|
@ -10,21 +10,27 @@
|
|||
"Proxy"
|
||||
],
|
||||
"author": "Software Ingenieur Begerad <dialog@SwIngBe.de>",
|
||||
"homepage": "https://git.wtf-eg.de/dancesWithCycles/gtfs-rt-proxy",
|
||||
"repository": "https://git.wtf-eg.de/dancesWithCycles/gtfs-rt-proxy",
|
||||
"bugs": "https://git.wtf-eg.de/dancesWithCycles/gtfs-rt-proxy/issues",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"engines": {
|
||||
"node": "<=18.19.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nodemon index.js",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "1.4.0",
|
||||
"axios": "1.6.2",
|
||||
"compression": "1.7.4",
|
||||
"cors": "2.8.5",
|
||||
"debug": "4.3.4",
|
||||
"dotenv": "16.3.1",
|
||||
"express": "4.18.2",
|
||||
"helmet": "7.0.0"
|
||||
"helmet": "7.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "2.0.16"
|
||||
"nodemon": "3.0.1"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue