question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server-side fetch request should have headers

See original GitHub issue

Fetch call made from the server should have the same headers, as the one made from the client.

<!-- index.svelte -->
<script context="module">

export async function load({ fetch }) {
  const { headers }  = await fetch('/content.json').then(res => res.json())
  return { 
    props: { headers }
  }
};

</script>
// content.json.ts
export const get = (request) => ({
  body: {
    headers: request.headers // <- headers: {} if requested during SSR, but populated otherwise
  }
});

In the above case the request.headers are empty ({}) if requested during SSR, but populated when requested from the client on navigation or if requested directly.

The expected behavior is that in both cases the headers are populated and requests look the same.

envinfo:

  npmPackages:
    @sveltejs/adapter-node: next => 1.0.0-next.10 
    @sveltejs/kit: next => 1.0.0-next.60 
    svelte: ^3.29.0 => 3.35.0 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:12
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

6reactions
Rich-Harriscommented, Apr 2, 2021

fetch in onMount is a reasonable workaround, yeah. We’ll get this fixed soon though, it’s a priority

5reactions
benwoodwardcommented, Aug 12, 2021

Without this feature I have a tree of components that need to wait for a follow up request before they can be rendered. The follow up request fetches the auth token from an endpoint. It slows the performance of the site down a lot, and also increases the complexity of my code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Fetch API - MDN Web Docs
Since headers can be sent in requests and received in responses, and have various limitations about what information can and should be mutable, ......
Read more >
Data Fetching: getServerSideProps - Next.js
Pages using getServerSideProps will be server side rendered at request time and only be cached if cache-control headers are configured. If you do...
Read more >
reactjs - 'ReferenceError: Headers is not defined' when using ...
I'm setting up a new application in React and I want it to be server side rendered. Unfortunately I'm not able to use...
Read more >
Different ways to fetch data in Next.js (server-side) and when ...
When building an application powered by Next.js it's probable that you'll need to fetch data from either a file, an internal API route...
Read more >
Making HTTP Requests in Node.js with node-fetch
A web application often needs to communicate with web servers to get various resources. You might need to fetch data from or post...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found