feat: make URL and DLOAD_FILE_NAME available via env file
This commit is contained in:
parent
94126ad0c0
commit
70faf12a9e
|
@ -1,4 +1,5 @@
|
|||
# Other
|
||||
*.bin
|
||||
*.csv
|
||||
.env~
|
||||
.env*
|
||||
|
|
|
@ -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'));
|
||||
|
|
14
index.js
14
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.');
|
||||
|
|
Loading…
Reference in New Issue