UND_ERR_REQ_CONTENT_LENGTH_MISMATCH error when navigating to index route
My index route looks like this
export function routeData() {
return createServerData$(async (_, { request, fetch: fetcher }) => {
const response = await fetcher("http://localhost:4000/api/users/self", {
...request,
credentials: "include",
headers: request.headers,
});
if (response.status !== 200) {
throw redirect("/login");
}
return response.json() as Promise<{ id: string }>;
});
}
const Root: VoidComponent = () => {
const data = useRouteData<typeof routeData>();
return (....)
}
export function routeData() {
return createServerData$(async (_, { request, fetch: fetcher }) => {
const response = await fetcher("http://localhost:4000/api/users/self", {
...request,
credentials: "include",
headers: request.headers,
});
if (response.status !== 200) {
throw redirect("/login");
}
return response.json() as Promise<{ id: string }>;
});
}
const Root: VoidComponent = () => {
const data = useRouteData<typeof routeData>();
return (....)
}
1 Reply
Refreshing makes it work again.
I can also see in my backend that the
This was because I was setting my headers manually.
I changed it to this:
and it works
fetch
never reaches my server.
TypeError: fetch failed
at fetch (/node_modules/.pnpm/undici@5.16.0/node_modules/undici/index.js:113:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.$$serverHandler0 (/src/routes/index.tsx:22:20)
at async Module.handleServerRequest (/@fs/node_modules/.pnpm/solid-start@0.2.17_xkldvgorozr2rd64n7towncbfe/node_modules/solid-start/server/server-functions/server.ts:173:20)
at async eval (/@fs/node_modules/.pnpm/solid-start@0.2.17_xkldvgorozr2rd64n7towncbfe/node_modules/solid-start/server/middleware.ts:41:30)
... 3 lines matching cause stack trace ...
at async startHandler (file:///node_modules/.pnpm/[email protected]_xkldvgorozr2rd64n7towncbfe/node_modules/solid-start/dev/server.js:115:20) {
cause: RequestContentLengthMismatchError: Request body length does not match content-length header
.......
code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
}
}
TypeError: fetch failed
at fetch (/node_modules/.pnpm/undici@5.16.0/node_modules/undici/index.js:113:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.$$serverHandler0 (/src/routes/index.tsx:22:20)
at async Module.handleServerRequest (/@fs/node_modules/.pnpm/solid-start@0.2.17_xkldvgorozr2rd64n7towncbfe/node_modules/solid-start/server/server-functions/server.ts:173:20)
at async eval (/@fs/node_modules/.pnpm/solid-start@0.2.17_xkldvgorozr2rd64n7towncbfe/node_modules/solid-start/server/middleware.ts:41:30)
... 3 lines matching cause stack trace ...
at async startHandler (file:///node_modules/.pnpm/[email protected]_xkldvgorozr2rd64n7towncbfe/node_modules/solid-start/dev/server.js:115:20) {
cause: RequestContentLengthMismatchError: Request body length does not match content-length header
.......
code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
}
}
export function routeData() {
return createServerData$(async (_, { request }) => {
const cookieHeaders = new Headers();
const cookie = request.headers.get("cookie");
if (cookie) {
cookieHeaders.set("cookie", cookie);
}
const response = await fetch("http://localhost:4000/api/users/self", {
...request,
credentials: "include",
headers: cookieHeaders,
});
if (response.status !== 200) {
throw redirect("/login");
}
return response.json() as Promise<{ id: string }>;
});
}
export function routeData() {
return createServerData$(async (_, { request }) => {
const cookieHeaders = new Headers();
const cookie = request.headers.get("cookie");
if (cookie) {
cookieHeaders.set("cookie", cookie);
}
const response = await fetch("http://localhost:4000/api/users/self", {
...request,
credentials: "include",
headers: cookieHeaders,
});
if (response.status !== 200) {
throw redirect("/login");
}
return response.json() as Promise<{ id: string }>;
});
}