this.fetch doesn't work with Fastify
Closed this issue · 5 comments
Describe the bug
req.socket.encrypted
from file middleware/get_page_handler.ts
is not available if the server is Fastify
Logs
Cannot read property 'encrypted' of undefined
TypeError: Cannot read property 'encrypted' of undefined
To Reproduce
Please, clone this repository: https://github.com/usernamus/sapper-fastify-socket and run the project
Click to blog link and refresh the page
Expected behavior
I expect to see a list of posts
Stacktraces
Stack trace
Cannot read property 'encrypted' of undefined
TypeError: Cannot read property 'encrypted' of undefined
at Object.fetch (my-app/src/node_modules/@sapper/server.mjs:4662:57)
at Object.preload (my-app/src/routes/blog/index.svelte:3:19)
at my-app/src/node_modules/@sapper/server.mjs:4707:57
at Array.map ()
at my-app/src/node_modules/@sapper/server.mjs:4701:63
at Generator.next ()
at fulfilled (my-app/src/node_modules/@sapper/server.mjs:128:61)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Information about your Sapper Installation:
System:
OS: macOS Mojave 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 790.80 MB / 8.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 14.9.0 - /usr/local/bin/node
npm: 6.14.7 - /usr/local/bin/npm
Browsers:
Chrome: 84.0.4147.135
Firefox: 80.0.1
Safari: 13.1
npmPackages:
rollup: ^2.3.4 => 2.26.9
sapper: ^0.28.3 => 0.28.3
svelte: ^3.17.3 => 3.24.1
Severity
It's blocking an upgrade and usage
Additional context
With req.connection.encrypted
working fine
If I remember correctly req.connection.encrypted
is deprecated and that's why we didn't use it
This isn't a bug, as I'd say it's entirely reasonable for Sapper to expect the req
object to at least have everything from Node's built-in IncomingMessage
object. If doing something like req.socket && req.socket.encrypted ? ... : ...
instead would work here, I think that would be a reasonable feature request.
@benmccann, I understand this, but there is such a situation with Fastify. I suggested this not as a solution, but as an example that the problem is exactly in this place
@Conduitry, do I need to replace this issue with a feature request?
I think that there's a larger question here around how do we support all types of other environments like AWS Lamda, Vercel, Cloudflare workers, etc. All of these may not have Node's APIs available. It'd be good to solve this in a holistic manner
This issue has already been tagged as an enhancement so no need to replace it with another one
SvelteKit has adapters for different environments. You should be able to adapter-node
to export a SvelteKit middleware for use in Fastify:
https://github.com/sveltejs/kit/tree/master/packages/adapter-node#middleware
Please use SvelteKit for this