Skip to content

Commit

Permalink
fix(FastifyServer): fix fastify responding early
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Sep 10, 2024
1 parent 7a5b728 commit 2459a91
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/servers/fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,30 @@ export class FastifyServer extends Server {
}
);

app.post(path, (req: any, res: any) =>
handler(
{
headers: req.headers,
body: req.body,
request: req,
response: res,
rawBody: req.rawBody
},
async (response) => {
res.status(response.status || 200);
if (response.headers) res.headers(response.headers);
if (response.files) {
const data = new MultipartData();
res.header('Content-Type', 'multipart/form-data; boundary=' + data.boundary);
for (const i in response.files)
data.attach(`files[${i}]`, response.files[i].file, response.files[i].name);
data.attach('payload_json', JSON.stringify(response.body));
res.send(Buffer.concat(data.finish()));
} else res.send(response.body);
}
)
app.post(
path,
(req: any, res: any) =>
void handler(
{
headers: req.headers,
body: req.body,
request: req,
response: res,
rawBody: req.rawBody
},
async (response) => {
res.status(response.status || 200);
if (response.headers) res.headers(response.headers);
if (response.files) {
const data = new MultipartData();
res.header('Content-Type', 'multipart/form-data; boundary=' + data.boundary);
for (const i in response.files)
data.attach(`files[${i}]`, response.files[i].file, response.files[i].name);
data.attach('payload_json', JSON.stringify(response.body));
res.send(Buffer.concat(data.finish()));
} else res.send(response.body);
}
)
);
});
}
Expand Down

0 comments on commit 2459a91

Please sign in to comment.