Replacing request.js with axios

fixes #153
This commit is contained in:
softsimon
2020-11-15 14:22:47 +07:00
parent 12b3ecd078
commit e7ddedaeb6
7 changed files with 1037 additions and 578 deletions

View File

@@ -4,7 +4,7 @@ import * as http from 'http';
import * as https from 'https';
import * as WebSocket from 'ws';
import * as cluster from 'cluster';
import * as request from 'request';
import axios from 'axios';
import { checkDbConnection } from './database';
import config from './config';
@@ -190,11 +190,13 @@ class Server {
;
} else {
this.app
.get(config.MEMPOOL.API_URL_PREFIX + 'donations', (req, res) => {
req.pipe(request('https://mempool.space/api/v1/donations')).pipe(res);
.get(config.MEMPOOL.API_URL_PREFIX + 'donations', async (req, res) => {
const response = await axios.get('https://mempool.space/api/v1/donations', { responseType: 'stream' });
response.data.pipe(res);
})
.get(config.MEMPOOL.API_URL_PREFIX + 'donations/images/:id', (req, res) => {
req.pipe(request('https://mempool.space/api/v1/donations/images/' + req.params.id)).pipe(res);
.get(config.MEMPOOL.API_URL_PREFIX + 'donations/images/:id', async (req, res) => {
const response = await axios.get('https://mempool.space/api/v1/donations/images/' + req.params.id, { responseType: 'stream' });
response.data.pipe(res);
});
}
}