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
|
# Other
|
||||||
|
*.bin
|
||||||
*.csv
|
*.csv
|
||||||
.env~
|
.env~
|
||||||
.env*
|
.env*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const axios=require('axios');
|
const axios=require('axios');
|
||||||
const debug=require('debug')('debug');
|
const debug=require('debug')('gtfs-rt');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
@ -10,7 +10,10 @@ router.get('/', async function(req, res, next) {
|
||||||
debug('gtfs-rt start...');
|
debug('gtfs-rt start...');
|
||||||
try {
|
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 = {
|
const config = {
|
||||||
responseType: 'arraybuffer'
|
responseType: 'arraybuffer'
|
||||||
//responseType: 'blob'
|
//responseType: 'blob'
|
||||||
|
@ -18,11 +21,14 @@ router.get('/', async function(req, res, next) {
|
||||||
|
|
||||||
const rspns = await axios.get(URL,config);
|
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, {
|
res.writeHead(200, {
|
||||||
//'Content-Type': mimetype,
|
//'Content-Type': mimetype,
|
||||||
'Content-Type': 'application/octet-stream',
|
'Content-Type': 'application/octet-stream',
|
||||||
'Content-disposition': 'attachment;filename=' + filename,
|
'Content-disposition': 'attachment;filename=' + DLOAD_FILE_NAME,
|
||||||
'Content-Length': rspns.data.length
|
'Content-Length': rspns.data.length
|
||||||
});
|
});
|
||||||
res.end(Buffer.from(rspns.data, 'binary'));
|
res.end(Buffer.from(rspns.data, 'binary'));
|
||||||
|
|
14
index.js
14
index.js
|
@ -5,25 +5,23 @@ const FS = require('fs');
|
||||||
DEBUG('index start...');
|
DEBUG('index start...');
|
||||||
const APP=require('./app/app');
|
const APP=require('./app/app');
|
||||||
|
|
||||||
//TODO make port available via config
|
|
||||||
//set port
|
//set port
|
||||||
const PORT=parseInt(process.env.PORT, 10)||65535;
|
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
|
//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') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
DEBUG('development mode');
|
DEBUG('index: development mode');
|
||||||
APP.listen(PORT);
|
APP.listen(PORT);
|
||||||
}else{
|
}else{
|
||||||
DEBUG('production mode');
|
DEBUG('index: production mode');
|
||||||
HTTPS.createServer({
|
HTTPS.createServer({
|
||||||
//TODO make key and cert available via config
|
//TODO make key and cert available via config
|
||||||
key: FS.readFileSync('./p'),
|
key: FS.readFileSync('./p'),
|
||||||
cert: FS.readFileSync('./f')
|
cert: FS.readFileSync('./f')
|
||||||
}, APP)
|
}, 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