-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodes-azurefunction.js
31 lines (23 loc) · 962 Bytes
/
nodes-azurefunction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { app } = require('@azure/functions');
const url = require('url');
// https://researchlab-cors-anywhere.azurewebsites.net/api/researchlab-cors-anywhere
app.http('researchlab-cors-anywhere', {
methods: ['GET', 'POST'],
authLevel: 'anonymous',
handler: async (request, context) => {
context.log(`Http function processed request for url "${request.url}"`);
if (request.body) {
let chunks = [];
const reader = request.body.getReader(); // Get the reader once
let chunk = await reader.read(); // Read the first chunk
while (!chunk.done) { // While there's data to read
chunks.push(chunk.value);
chunk = await reader.read(); // Read the next chunk
}
// Once all chunks are read, release the lock
reader.releaseLock();
let body = Buffer.concat(chunks); // Concatenate all chunks into a single buffer
return { body: body.toString() };
}
}
});