unjs / unenv

🕊️ Convert javaScript code to be runtime agnostic
MIT License
383 stars 20 forks source link

Make the platform's context available #72

Closed dario-piotrowicz closed 1 year ago

dario-piotrowicz commented 1 year ago

Describe the feature

Hi, I'm trying to create a Nuxt application and deploy it via Cloudflare Pages

When you deploy an application via Cloudflare Pages you can access other Cloudflare products via bindings (which basically allow you to store data, etc...)

The issue is that I believe that such bindings are not made accessible via H3 (I expected to maybe find them in the H3EventContext but no luck, as you can see here: my gh nuxt get context test (deployed here))

Edge Frameworks which I am used to all make such context available, like for example:

Additional information

dario-piotrowicz commented 1 year ago

Note, the context needs to be passed by nitro first which is currently not happening: https://github.com/unjs/nitro/issues/773

pi0 commented 1 year ago

A main blocker was that we were not able to pass a context to direct calls. It is now supported by https://github.com/unjs/unenv/commit/a9190c4120aa3ab2edcbb77f780f9e3f60b47c55 in latest version of unenv.

dario-piotrowicz commented 1 year ago

@pi0 the context being passed doesn't seem the one needed for the bindings as it only contains the cf property

For example This is what I get as the `__unenv__`: ``` { "cf": { "clientTcpRtt": 7, "longitude": "-0.02000", "latitude": "51.50640", "tlsCipher": "AEAD-AES128-GCM-SHA256", "continent": "EU", "asn": 62240, "clientAcceptEncoding": "gzip, deflate, br", "country": "GB", "tlsClientAuth": { "certIssuerDNLegacy": "", "certIssuerSKI": "", "certSubjectDNRFC2253": "", "certSubjectDNLegacy": "", "certFingerprintSHA256": "", "certNotBefore": "", "certSKI": "", "certSerial": "", "certIssuerDN": "", "certVerified": "NONE", "certNotAfter": "", "certSubjectDN": "", "certPresented": "0", "certRevoked": "0", "certIssuerSerial": "", "certIssuerDNRFC2253": "", "certFingerprintSHA1": "" }, "tlsExportedAuthenticator": { "clientFinished": "af098786dc0a4996504582441f67990e9d95dc42c0f8b87a0a7b6c9e64ea9d6c", "clientHandshake": "337673d8550864b28651944a2cfb490dd1e3f310b1f10aff73ec933bfcef6443", "serverHandshake": "56ea288808e63f90fbe37eaf5ebde08df1abc198374edca2764b1eb3e7f95380", "serverFinished": "f896a7647eddb7a3ee762883d40292f175165a96eba9f3c658c5ae3d337ed95a" }, "tlsVersion": "TLSv1.3", "colo": "LHR", "timezone": "Europe/London", "city": "London", "edgeRequestKeepAliveStatus": 1, "requestPriority": "weight=256;exclusive=1", "httpProtocol": "HTTP/2", "region": "England", "regionCode": "ENG", "asOrganization": "Clouvider Limited", "postalCode": "E14" } } ``` it does not contain the `env` and `ctx` that Cloudflare provides (alongside the request). For context here you can see the `env` and `ctx` I am referring to: [![Screenshot at 2023-02-19 16-43-01](https://user-images.githubusercontent.com/61631103/219962008-a547d63a-3c61-48c0-9db3-9c176344c3ab.png) ](https://developers.cloudflare.com/workers/runtime-apis/kv/#reading-key-value-pairs)

~Anyways unless I am mistaken that unenv change isn't actually related to the issue at hand since the issue is not around getting something when we manually fetch but getting some platform specific data in the incoming request~

dario-piotrowicz commented 1 year ago

@pi0 the context there was indeed relevant :sweat_smile: , with that seems like the fix to the problem is quite simple: https://github.com/unjs/nitro/pull/997