Spaces:
Paused
Paused
| const express = require('express'); | |
| const axios = require('axios'); | |
| const { default: PQueue } = require('p-queue'); | |
| const API_ENDPOINT = process.env.API_ENDPOINT; | |
| const PORT = process.env.PORT || 3000; | |
| const WORKER_CONCURRENCY = process.env.WORKER_CONCURRENCY || 5; | |
| const app = express(); | |
| app.use(express.json()); | |
| const queue = new PQueue({ concurrency: WORKER_CONCURRENCY }); | |
| app.post('/endpoint', function(req, res) { | |
| queue.add(async () => { | |
| try { | |
| const response = await axios.post(API_ENDPOINT, req.body); | |
| res.send(response.data); | |
| } catch (error) { | |
| res.status(500).send(error.message); | |
| } | |
| }); | |
| }); | |
| app.listen(PORT, () => console.log(`Server is running on port ${PORT}`)); |