Skip to content

Commit 04fd04d

Browse files
committed
fix: Added multipart: true to post endpoints
1 parent e0e7587 commit 04fd04d

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

app.js

+6
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ async function startServer() {
145145
method: "POST",
146146
path: "/parse",
147147
options: {
148+
payload: {
149+
multipart: true
150+
},
148151
handler: async (request, h) => {
149152
try {
150153
const options = await buildOptions(request);
@@ -163,6 +166,9 @@ async function startServer() {
163166
method: "POST",
164167
path: "/count",
165168
options: {
169+
payload: {
170+
multipart: true
171+
},
166172
handler: async (request, h) => {
167173
try {
168174
const options = await buildOptions(request);

static/javascript/testrunner.js

+30-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function passTest( test, callback ){
7979
var dom = new DOMParser(),
8080
doc = dom.parseFromString( test.html, 'text/html' );
8181

82-
getResults( test.html, '/parse/', function(err, mfJSON ){
82+
getResults( test.html, '/parse', function(err, mfJSON ){
8383
if(mfJSON){
8484
// diff json
8585
var diff = DeepDiff(JSON.parse(test.json), mfJSON);
@@ -188,7 +188,7 @@ function getResults( html, url, callback ){
188188
formData.append('dateFormat', 'html5');
189189

190190
var request = new XMLHttpRequest();
191-
request.open("POST", url);
191+
request.open("POST", url, true);
192192
request.send(formData);
193193

194194
request.onload = function(e) {
@@ -198,4 +198,31 @@ function getResults( html, url, callback ){
198198
callback("Error " + request.status, null);
199199
}
200200
};
201-
}
201+
}
202+
203+
/*
204+
// post form and returns JSON
205+
async function getResults(html, url) {
206+
const formData = new FormData();
207+
formData.append('html', html);
208+
formData.append('baseUrl', 'http://example.com');
209+
formData.append('dateFormat', 'html5');
210+
211+
try {
212+
const response = await fetch(url, {
213+
method: 'POST',
214+
body: formData
215+
});
216+
217+
if (!response.ok) {
218+
throw new Error(`HTTP error! status: ${response.status}`);
219+
} else {
220+
const json = await response.json();
221+
return json;
222+
}
223+
} catch (error) {
224+
console.error('There was a problem with the fetch operation: ' + error.message);
225+
}
226+
}
227+
228+
*/

0 commit comments

Comments
 (0)