Skip to content

Commit c28a8d9

Browse files
authored
Simplify multipart requests by dropping manually encoding (#122)
* Remove `express-fileupload` package * Drop manually encoding multipart requests
1 parent 051ae0f commit c28a8d9

4 files changed

Lines changed: 1 addition & 150 deletions

File tree

‎package-lock.json‎

Lines changed: 0 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"@timfish/forge-externals-plugin": "^0.2.1",
4848
"@types/archiver": "^6.0.2",
4949
"@types/ejs": "^3.1.5",
50-
"@types/express-fileupload": "1.5.0",
5150
"@types/jest": "^29.5.11",
5251
"@types/react": "^18.2.42",
5352
"@types/react-dom": "^18.2.17",
@@ -108,7 +107,6 @@
108107
"date-fns": "^3.3.1",
109108
"electron-squirrel-startup": "^1.0.0",
110109
"express": "4.19.2",
111-
"express-fileupload": "1.4.0",
112110
"file-stream-rotator": "^1.0.0",
113111
"follow-redirects": "1.15.6",
114112
"fs-extra": "11.1.1",

‎vendor/wp-now/src/encode-as-multipart.ts‎

Lines changed: 0 additions & 45 deletions
This file was deleted.

‎vendor/wp-now/src/start-server.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { HTTPMethod } from '@php-wasm/universal';
44
import express from 'express';
55
import compression from 'compression';
66
import compressible from 'compressible';
7-
import fileUpload from 'express-fileupload';
87
import { portFinder } from './port-finder';
98
import { NodePHP } from '@php-wasm/node';
109
import startWPNow from './wp-now';
1110
import { output } from './output';
1211
import { addTrailingSlash } from './add-trailing-slash';
13-
import { encodeAsMultipart } from './encode-as-multipart';
1412

1513
const requestBodyToBytes = async ( req ): Promise< Uint8Array > =>
1614
await new Promise( ( resolve ) => {
@@ -45,7 +43,6 @@ export async function startServer(
4543
);
4644
}
4745
const app = express();
48-
app.use(fileUpload({ defCharset: 'utf8', defParamCharset: 'utf8'}));
4946
app.use(compression({ filter: shouldCompress }));
5047
app.use(addTrailingSlash('/wp-admin'));
5148
const port = options.port ?? await portFinder.getOpenPort();
@@ -61,19 +58,11 @@ export async function startServer(
6158
}
6259
}
6360

64-
let body: Uint8Array;
65-
if ( requestHeaders[ 'content-type' ]?.startsWith( 'multipart/form-data' ) ) {
66-
const multipart = await encodeAsMultipart( req );
67-
body = multipart.bytes;
68-
requestHeaders[ 'content-type' ] = multipart.contentType;
69-
} else {
70-
body = await requestBodyToBytes( req );
71-
}
7261
const data = {
7362
url: req.url,
7463
headers: requestHeaders,
7564
method: req.method as HTTPMethod,
76-
body,
65+
body: await requestBodyToBytes( req ),
7766
};
7867
const resp = await php.request(data);
7968
res.statusCode = resp.httpStatusCode;

0 commit comments

Comments
 (0)