[about page] proxy community sponsors apis to prod, small refactor
This commit is contained in:
		
							parent
							
								
									7e16d550b0
								
							
						
					
					
						commit
						dab9357b40
					
				
							
								
								
									
										87
									
								
								backend/src/api/about.routes.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								backend/src/api/about.routes.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,87 @@ | ||||
| import { Application } from "express"; | ||||
| import config from "../config"; | ||||
| import axios from "axios"; | ||||
| import logger from "../logger"; | ||||
| 
 | ||||
| class AboutRoutes { | ||||
|   public initRoutes(app: Application) { | ||||
|     app | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'donations', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/donations`, { responseType: 'stream', timeout: 10000 }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'donations/images/:id', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/donations/images/${req.params.id}`, { | ||||
|             responseType: 'stream', timeout: 10000 | ||||
|           }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'contributors', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/contributors`, { responseType: 'stream', timeout: 10000 }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'contributors/images/:id', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/contributors/images/${req.params.id}`, { | ||||
|             responseType: 'stream', timeout: 10000 | ||||
|           }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'translators', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/translators`, { responseType: 'stream', timeout: 10000 }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'translators/images/:id', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/translators/images/${req.params.id}`, { | ||||
|             responseType: 'stream', timeout: 10000 | ||||
|           }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'services/sponsors', async (req, res) => { | ||||
|         const url = `${config.MEMPOOL_SERVICES.API}/${req.originalUrl.replace('/api/v1/services/', '')}`; | ||||
|         try { | ||||
|           const response = await axios.get(url, { responseType: 'stream', timeout: 10000 }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           logger.err(`Unable to fetch sponsors from ${url}. ${e}`, 'About Page'); | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'services/account/images/:username', async (req, res) => { | ||||
|         const url = `${config.MEMPOOL_SERVICES.API}/${req.originalUrl.replace('/api/v1/services/', '')}`; | ||||
|         try { | ||||
|           const response = await axios.get(url, { responseType: 'stream', timeout: 10000 }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           logger.err(`Unable to fetch sponsor profile image from ${url}. ${e}`, 'About Page'); | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|     ; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| export default new AboutRoutes(); | ||||
| @ -37,60 +37,6 @@ class BitcoinRoutes { | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'replacements', this.getRbfReplacements) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'fullrbf/replacements', this.getFullRbfReplacements) | ||||
|       .post(config.MEMPOOL.API_URL_PREFIX + 'tx/push', this.$postTransactionForm) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'donations', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/donations`, { responseType: 'stream', timeout: 10000 }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'donations/images/:id', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/donations/images/${req.params.id}`, { | ||||
|             responseType: 'stream', timeout: 10000 | ||||
|           }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'contributors', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/contributors`, { responseType: 'stream', timeout: 10000 }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'contributors/images/:id', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/contributors/images/${req.params.id}`, { | ||||
|             responseType: 'stream', timeout: 10000 | ||||
|           }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'translators', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/translators`, { responseType: 'stream', timeout: 10000 }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'translators/images/:id', async (req, res) => { | ||||
|         try { | ||||
|           const response = await axios.get(`${config.EXTERNAL_DATA_SERVER.MEMPOOL_API}/translators/images/${req.params.id}`, { | ||||
|             responseType: 'stream', timeout: 10000 | ||||
|           }); | ||||
|           response.data.pipe(res); | ||||
|         } catch (e) { | ||||
|           res.status(500).end(); | ||||
|         } | ||||
|       }) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'blocks', this.getBlocks.bind(this)) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'blocks/:height', this.getBlocks.bind(this)) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'block/:hash', this.getBlock) | ||||
|  | ||||
| @ -43,6 +43,7 @@ import redisCache from './api/redis-cache'; | ||||
| import accelerationApi from './api/services/acceleration'; | ||||
| import bitcoinCoreRoutes from './api/bitcoin/bitcoin-core.routes'; | ||||
| import bitcoinSecondClient from './api/bitcoin/bitcoin-second-client'; | ||||
| import aboutRoutes from './api/about.routes'; | ||||
| 
 | ||||
| class Server { | ||||
|   private wss: WebSocket.Server | undefined; | ||||
| @ -305,6 +306,7 @@ class Server { | ||||
|       nodesRoutes.initRoutes(this.app); | ||||
|       channelsRoutes.initRoutes(this.app); | ||||
|     } | ||||
|     aboutRoutes.initRoutes(this.app); | ||||
|   } | ||||
| 
 | ||||
|   healthCheck(): void { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user