multimodalart HF Staff commited on
Commit
93293f1
·
1 Parent(s): b479503

Create app.js

Browse files
Files changed (1) hide show
  1. app.js +25 -0
app.js ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const axios = require('axios');
3
+ const { default: PQueue } = require('p-queue');
4
+
5
+ const API_ENDPOINT = process.env.API_ENDPOINT;
6
+ const PORT = process.env.PORT || 3000;
7
+ const WORKER_CONCURRENCY = process.env.WORKER_CONCURRENCY || 5;
8
+
9
+ const app = express();
10
+ app.use(express.json());
11
+
12
+ const queue = new PQueue({ concurrency: WORKER_CONCURRENCY });
13
+
14
+ app.post('/endpoint', function(req, res) {
15
+ queue.add(async () => {
16
+ try {
17
+ const response = await axios.post(API_ENDPOINT, req.body);
18
+ res.send(response.data);
19
+ } catch (error) {
20
+ res.status(500).send(error.message);
21
+ }
22
+ });
23
+ });
24
+
25
+ app.listen(PORT, () => console.log(`Server is running on port ${PORT}`));