diff --git a/.gitignore b/.gitignore index efdbaf3..069d1a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Other +*.bin *.csv .env~ .env* diff --git a/app/route/gtfs-rt.js b/app/route/gtfs-rt.js index 74de30b..6666809 100644 --- a/app/route/gtfs-rt.js +++ b/app/route/gtfs-rt.js @@ -1,5 +1,5 @@ const axios=require('axios'); -const debug=require('debug')('debug'); +const debug=require('debug')('gtfs-rt'); const express = require('express'); const router = express.Router(); @@ -10,7 +10,10 @@ router.get('/', async function(req, res, next) { debug('gtfs-rt start...'); try { - const URL='http://gtfsr.vbn.de/gtfsr_connect.bin'; + //set url + const URL = process.env.URL || 'http://localhost:65535/gtfs-rt.bin'; + debug('gtfs-rt:get() URL: ' + URL ); + const config = { responseType: 'arraybuffer' //responseType: 'blob' @@ -18,11 +21,14 @@ router.get('/', async function(req, res, next) { const rspns = await axios.get(URL,config); - const filename = 'gtfs-rt.bin'; + //set url + 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=' + filename, + 'Content-disposition': 'attachment;filename=' + DLOAD_FILE_NAME, 'Content-Length': rspns.data.length }); res.end(Buffer.from(rspns.data, 'binary')); diff --git a/index.js b/index.js index db00901..4e64340 100644 --- a/index.js +++ b/index.js @@ -5,25 +5,23 @@ 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); +DEBUG('index: PORT: ' + PORT); -//TODO make env available via config //pass 'APP' to server -DEBUG('NODE_ENV: '+process.env.NODE_ENV); +DEBUG('index: NODE_ENV: ' + process.env.NODE_ENV); if (process.env.NODE_ENV !== 'production') { - DEBUG('development mode'); + DEBUG('index: development mode'); APP.listen(PORT); }else{ - DEBUG('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('listening on port '+PORT)); + .listen(PORT, ()=>DEBUG('index: listening on port '+PORT)); } -DEBUG('index done.'); +DEBUG('index: index done.'); diff --git a/readme.md b/readme.md index ae035a9..bbf2f26 100644 --- a/readme.md +++ b/readme.md @@ -12,8 +12,14 @@ Requirements: npm i ``` -# Test +# Development Setup ``` -DEBUG=debug,index npm run dev +DEBUG=gtfs-rt,debug,index npm run dev ``` + +# Test +``` +curl http://localhost:65532/ +curl http://localhost:65532/gtfs-rt --output gtfs-rt.bin +``` \ No newline at end of file