Skip to content

Commit 37604c2

Browse files
committed
🐛 multipart/form-data without boundary #276
1 parent a422a42 commit 37604c2

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

layers/common/composables/UseApiRouteFetcher.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,27 @@ export const apiResponseEventBus = useEventBus<ApiResponseEvent, ApiResponseCont
2525
* * default - application/json, text/html
2626
*
2727
* @see https://github.com/unjs/ofetch/blob/main/src/fetch.ts
28+
* @see https://github.com/trydofor/professional-razor/issues/97
2829
*/
2930
export function apiRequestAcceptContentHook(accept = 'application/json, text/html', id = 'requestAcceptContent'): ApiRequestHook & { id: string } {
31+
const vitest = typeof process !== 'undefined' && process.env.VITEST === 'true';
3032
return attachId(id, (context) => {
3133
const body = context.options.body;
3234
const headers = context.options.headers;
3335

3436
if (!headers.has('content-type')) {
35-
let contentType = 'application/json';
3637
if (body instanceof URLSearchParams) {
37-
contentType = 'application/x-www-form-urlencoded';
38+
headers.set('content-type', 'application/x-www-form-urlencoded');
3839
}
3940
else if (body instanceof FormData) {
40-
contentType = 'multipart/form-data';
41+
if (vitest) {
42+
// just for testing, browser autoset, node ssr, should not here
43+
headers.set('content-type', 'multipart/form-data');
44+
}
45+
}
46+
else {
47+
headers.set('content-type', 'application/json');
4148
}
42-
headers.set('content-type', contentType);
4349
}
4450

4551
if (!context.options.headers.has('accept')) {

layers/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fessional/razor-common",
3-
"version": "0.8.1-dev.14",
3+
"version": "0.8.1-dev.15",
44
"description": "common layer for mobile and desktop",
55
"type": "module",
66
"main": "./nuxt.config.ts",

layers/desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fessional/razor-desktop",
3-
"version": "0.8.1-dev.14",
3+
"version": "0.8.1-dev.15",
44
"description": "desktop layer with vuetify",
55
"type": "module",
66
"main": "./nuxt.config.ts",

layers/mobile/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fessional/razor-mobile",
3-
"version": "0.8.1-dev.14",
3+
"version": "0.8.1-dev.15",
44
"description": "mobile layer with ionic and capacitor",
55
"type": "module",
66
"main": "./nuxt.config.ts",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fessional/razor",
3-
"version": "0.8.1-dev.14",
3+
"version": "0.8.1-dev.15",
44
"description": "Use front-end tech (Nuxt/Ts) to build multi-platform from one codebase, suitable for small team and app to write app once, apply almost anywhere.",
55
"type": "module",
66
"files": [

0 commit comments

Comments
 (0)