Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to fix POST method #8

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bling/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const fetchMethods: CreateClientFetcherMethods = {
resolvedHref,
mergeRequestInits(
baseInit,
payloadInit,
method === 'POST' ? payloadInit : undefined,
defaultOpts?.request,
opts?.request,
),
Expand Down
24 changes: 12 additions & 12 deletions packages/bling/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,15 @@ export function mergeHeaders(...objs: (Headers | HeadersInit | undefined)[]) {
}

export function mergeRequestInits(...objs: (RequestInit | undefined)[]) {
return Object.assign.call(null, [
{},
...objs,
{ headers: mergeHeaders(...objs.map((o) => o && o.headers)) },
])
const out = {} as Record<keyof RequestInit, any>
for (const obj of objs) {
if (!obj) continue
for (const key in obj) {
out[key as keyof RequestInit] = obj[key as keyof RequestInit]
}
}
out.headers = mergeHeaders(...objs.map((o) => o && o.headers))
return out as RequestInit
}

export async function parseResponse(response: Response) {
Expand Down Expand Up @@ -204,13 +208,9 @@ export async function parseResponse(response: Response) {
}

export function mergeFetchOpts(...objs: (FetchFnCtxOptions | undefined)[]) {
return Object.assign.call(null, [
{},
...objs,
{
request: mergeRequestInits(...objs.map((o) => o && o.request)),
},
])
return Object.assign.call(null, {}, ...objs, {
request: mergeRequestInits(...objs.map((o) => o && o.request)),
})
}

export function payloadRequestInit(
Expand Down