gtfs-rt-proxy/app/route/gtfs-rt.js

43 lines
1.1 KiB
JavaScript

const axios=require('axios');
const debug=require('debug')('gtfs-rt');
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 {
//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'
};
const rspns = await axios.get(URL,config);
//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=' + DLOAD_FILE_NAME,
'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;