Skip to content

Commit

Permalink
dep(server)!: bump forever@4.0.3, iconv@3.0.1, busboy@1.6.0 & rebuilt…
Browse files Browse the repository at this point in the history
… package-lock (#370)

* dep(server): bump forever@4.0.3, iconv@3.0.1, & rebuilt package-lock w/ v2 lock
* dep(server)!: bump busboy@1.6.0
* refactor(server): apply additional changes to match busboy docs
  • Loading branch information
erisu committed Sep 5, 2023
1 parent dd9e922 commit ea31d29
Show file tree
Hide file tree
Showing 3 changed files with 4,018 additions and 671 deletions.
25 changes: 13 additions & 12 deletions tests/server/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const http = require('http');
const stringify = require('json-stringify-safe');
const Busboy = require('busboy');
const busboy = require('busboy');
const { Iconv } = require('iconv');

const port = process.env.PORT || 5001;
Expand All @@ -15,26 +15,27 @@ function parseMultipartForm (req, res, finishCb) {

const fields = {};
const files = {};
const busboy = new Busboy({ headers: req.headers });
const bb = busboy({ headers: req.headers });

busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
bb.on('file', (name, file, info) => {
const { filename } = info;
const currentFile = { size: 0 };

file.on('data', function (data) {
file.on('data', (data) => {
currentFile.name = filename;
currentFile.size += data.length;
});

file.on('end', function () {
file.on('close', () => {
files.file = currentFile;
});
});

busboy.on('field', function (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
fields[fieldname] = val;
bb.on('field', (name, val, info) => {
fields[name] = val;
});

busboy.on('finish', function () {
bb.on('close', () => {
console.log(stringify({ fields, files }));

// This is needed due to this bug: https://github.com/mscdex/busboy/issues/73
Expand All @@ -43,15 +44,15 @@ function parseMultipartForm (req, res, finishCb) {
}
});

busboy.on('error', function (err) {
bb.on('error', function (err) {
console.error(`error: ${err}: ${JSON.stringify(err)}`);
errorOccured = true;

res.writeHead(400, { 'Content-Type': 'text/plain' });
res.end(`Could not parse multipart form: ${err}\n`);
});

req.pipe(busboy);
req.pipe(bb);
}

function respondWithParsedForm (req, res, parseResultObj) {
Expand Down Expand Up @@ -115,7 +116,7 @@ http.createServer(function (req, res) {
req.on('data', function (chunk) {
body += chunk;
if (body.length > DIRECT_UPLOAD_LIMIT) {
req.connection.destroy();
req.socket.destroy();
}
});

Expand Down Expand Up @@ -150,7 +151,7 @@ http.createServer(function (req, res) {
res.end('404\n');
}

console.log(req.connection.remoteAddress + ' ' + req.method + ' ' + req.url + ' ' + res.statusCode + ' ' + req.headers['user-agent']);
console.log(req.socket.remoteAddress + ' ' + req.method + ' ' + req.url + ' ' + res.statusCode + ' ' + req.headers['user-agent']);
}).listen(port, '0.0.0.0');

console.log('Server running on ' + port);

0 comments on commit ea31d29

Please sign in to comment.