Skip to content

Commit dc9f711

Browse files
committed
add support for multiple requests
1 parent 9c19508 commit dc9f711

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

packages/insomnia/src/main/api-process.mjs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ import fs from 'node:fs';
55
import express from 'express';
66

77
const app = express();
8-
app.use(express.text()); // if you want raw text body
9-
// app.use(express.json()); // use this instead if sending JSON
8+
app.use(express.json()); // use this instead if sending JSON
9+
app.use(express.text({ type: 'text/plain' }));
1010

1111
app.post('/upload', (req, res) => {
12-
const content = req.body; // the raw POST body
13-
process.parentPort.postMessage({ body: content });
12+
const content = req.body;
13+
if (!content) {
14+
res.status(400).send('No content received');
15+
return;
16+
}
17+
process.parentPort.postMessage({ curlRequests: [content] });
1418
res.send('Received: ' + content);
1519
});
1620

21+
app.post('/upload-array', (req, res) => {
22+
const content = req.body;
23+
res.send('Received: ' + JSON.stringify(content));
24+
process.parentPort.postMessage({ curlRequests: content.list });
25+
});
1726
app.listen(8080, () => console.log('Server running on http://localhost:8080'));

packages/insomnia/src/main/ipc/main.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,29 @@ export function registerMainHandlers() {
231231
});
232232
apiProcess.on('message', async msg => {
233233
console.log('[api-process] received message:', msg);
234-
const resources = await convert(msg.body);
235-
console.log('[api-process] converted to resources:', resources);
236-
if (resources && !('convertErrorMessage' in resources) && resources.length > 0) {
237-
const req = resources[0] as unknown as Partial<Request>;
238-
let url = '';
239-
for (const window of BrowserWindow.getAllWindows()) {
240-
url = window.webContents.getURL();
234+
if (!msg.curlRequests || !Array.isArray(msg.curlRequests)) {
235+
console.warn('[api-process] invalid message format, missing curlRequests array');
236+
return;
237+
}
238+
for (const request of msg.curlRequests) {
239+
const resources = await convert(request);
240+
console.log('[api-process] converted to resources:', resources);
241+
if (resources && !('convertErrorMessage' in resources) && resources.length > 0) {
242+
const req = resources[0] as unknown as Partial<Request>;
243+
let url = '';
244+
for (const window of BrowserWindow.getAllWindows()) {
245+
url = window.webContents.getURL();
246+
}
247+
248+
const workspaceId = url.match(/wrk_[a-zA-Z0-9]+/)?.[0];
249+
console.log('[api-process] got workspace:', workspaceId);
250+
await models.request.create({
251+
...req,
252+
_id: undefined,
253+
name: req.url,
254+
parentId: workspaceId || 'wrk_scratchpad',
255+
});
241256
}
242-
const workspaceId = url.match(/wrk_[a-zA-Z0-9]+/)?.[0];
243-
console.log('[api-process] got workspace:', workspaceId);
244-
await models.request.create({
245-
...req,
246-
_id: undefined,
247-
name: req.url,
248-
parentId: workspaceId || 'wrk_scratchpad',
249-
});
250257
for (const window of BrowserWindow.getAllWindows()) {
251258
window.webContents.send('reload-from-mcp');
252259
}

0 commit comments

Comments
 (0)