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.

Clarify response vs request headers for the setup.js `getContext` function

See original GitHub issue

Describe the bug Whenever the prepare function of src/setup.js returns anything (headers, etc.), the HTTP endpoint causes an Error: Transferred a partial file. This does not happen if the prepare function is not present or does not return anything.

Logs

There is not much to see here. I’ve only tested the endpoints using Insomnia, so no browser logs. (Though, I suspect there wouldn’t be any aside from the aforementioned partial fire error.)

yarn run v1.22.5
warning package.json: No license field
$ svelte-kit dev
(node:83958) ExperimentalWarning: The ESM module loader is experimental.
> Listening on http://localhost:3000

To Reproduce The issue happens after a fresh install of Kit. My setup options were to disable TS in components, and to use SCSS for preprocessing.

I’ve made a repo to show exactly where the issue occurs: @didier/svelte-kit-broken-endpoints. See src/setup.js for an example.

Expected behavior I would expect the endpoint to send a respond, irregardless of whatever the prepare function does and returns.

Stacktraces None, no visible errors occur besides the HTTP client warning me of the Error: Transferred a partial file.

Information about your SvelteKit Installation:

System:
  OS: macOS 11.2.3
  CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
  Memory: 156.12 MB / 16.00 GB
  Shell: 5.8 - /bin/zsh

Binaries:
  Node: 12.17.0 - ~/.nvm/versions/node/v12.17.0/bin/node
  Yarn: 1.22.5 - /usr/local/bin/yarn
  npm: 6.14.4 - ~/.nvm/versions/node/v12.17.0/bin/npm
  Watchman: 4.9.0 - /usr/local/bin/watchman

Browsers:
  Brave Browser: 89.1.21.77
  Firefox: 83.0
  Firefox Developer Edition: 85.0
  Firefox Nightly: 74.0a1
  Safari: 14.0.3

npmPackages:
  @sveltejs/kit: ^1.0.0-next.55 => 1.0.0-next.55 
  svelte: ^3.29.0 => 3.35.0

Severity This issue is blocking usage of SvelteKit entirely, as HTTP Endpoints are part of the core functionality.

Additional context I’ve had contact with @antony about this. Raising the issue here so other contributors can take a look.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
GrygrFlzrcommented, Mar 26, 2021

Closing since getContext no longer returns a response header, and handle takes in a request object instead, so there’s no longer a header -> header function signature.

0reactions
Rich-Harriscommented, Mar 25, 2021

Note that prepare has been replaced by getContext: https://kit.svelte.dev/docs#hooks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Response.headers - Web APIs | MDN
The headers read-only property of the Response interface contains the Headers object associated with the response. Value. A Headers object.
Read more >
Accessing the web page's HTTP Headers in JavaScript
If an HTTP request is made over AJAX, it is possible to get the response headers with the getAllResponseHeaders() method. It's part of...
Read more >
Reference information for accessing the context object - IBM
You can reference context variables in user-defined policies with the getContext() and setContext() functions and with JavaScript dot ...
Read more >
Understanding response headers policies - Amazon CloudFront
You can use a response headers policy to specify the HTTP headers that Amazon CloudFront adds to responses that it sends to viewers....
Read more >
Write stored procedures, triggers, and UDFs in Azure Cosmos ...
You can write your logic in JavaScript and execute it inside the ... function () { var context = getContext(); var response =...
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