Skip to content

Commit

Permalink
Manual test script
Browse files Browse the repository at this point in the history
  • Loading branch information
rafasofizada committed Oct 20, 2022
1 parent 5a20470 commit e0d3ad9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions manual-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { createServer } from "http";
import { parseFormData } from ".";
import { DefaultField } from "./types";

createServer(
async (req, res) => {
try {
const { fields, files } = await parseFormData(
req,
{
"file1": {
maxFileByteLength: 0.05 * 1024 * 1024,
maxFileCount: 3
},
"file2": {
maxFileByteLength: 2 * 1024 * 1024,
maxFileCount: 0
},
[DefaultField]: {
maxFileByteLength: 0.01 * 1024 * 1024,
maxFileCount: 1
}
},
undefined,
{ limits: { fields: 2, files: 4 } }
);

console.log(fields);

for await (const { byteLength, stream, ...restFile } of files) {
stream.resume();

console.log({
...restFile,
byteLength: await byteLength
});
}
} catch (error) {
console.error(error);
}

res.end('');
}
)
.listen(3000);

console.log("Started");
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"module": "CommonJS",
"sourceMap": true
},
"include": ["index.ts", "server.ts"],
"include": ["index.ts", "manual-test.ts"],
"exclude": ["node_modules"]
}

0 comments on commit e0d3ad9

Please sign in to comment.