unenv icon indicating copy to clipboard operation
unenv copied to clipboard

`node:https.request` support

Open fl0wo opened this issue 1 year ago • 13 comments

Describe the feature

Hi, just to make sure, is https.request implemented for cloudflare?

If not, do you think there an ETA for it? I'd love to help if possible.

Additional information

  • [X] Would you be willing to help implement this feature?
### Tasks

fl0wo avatar Oct 10 '24 14:10 fl0wo

Any update on this?

fl0wo avatar Oct 16 '24 18:10 fl0wo

I'm also interested in this. @fl0wo have you found any workaround in the meantime?

keiwanmosaddegh avatar Nov 01 '24 13:11 keiwanmosaddegh

Hi, just to make sure, is https.request implemented for cloudflare?

confirmed that it is not.

Could you please expand on the use case?

vicb avatar Nov 01 '24 20:11 vicb

Hi, just to make sure, is https.request implemented for cloudflare?

confirmed that it is not.

Could you please expand on the use case?

I'm quite new to Cloudflare workers and all so there might be a clear solution for my issue, however I haven't been able to troubleshoot myself to something.

I'm building a Worker API that uses Firebase App Check for Auth. I'm getting the uenv not implemented error when using the App Check library. That's why I'm in need of it. Let me know if I can help by elaborating further. @vicb

keiwanmosaddegh avatar Nov 01 '24 21:11 keiwanmosaddegh

As you probably already knows Workers use the workerd Runtime that does not implement all of the Node.js APIs.

However we are looking at supporting more and more of the Node libs.

There are a few things that can help here:

  • cloudflare implementing the missing APIs
  • unenv polyfilling the missing APIs
  • libraries being updated to run on the edge by using Web APIs instead of the Node APIs

So what you can do here to help is:

  • Create an issue on the firebase repo explaining that you want to run the code at the edge and asking for Web APIs support (i.e. fetch)
  • Create a discussion on the workerd repo explaining what repo/version/API you would like to see supported - please link to this issue, the issue on the firebase repo and mention me there

And we'll get that working.

Thanks!

vicb avatar Nov 02 '24 06:11 vicb

Ideally, i would love to have a polyfill based on wintercg web sockets proposal which workerd currently support (startTLS) — and it should enable a universal / spec compatible solution in the future.

Native workerd support would be cool but i think it is still viable to be discussed for unenv support :)

—-

I think we should also investigate firebase SDK issue separately, i guess it can be solved by making sure it leverages fetch for http calls (unless they really need TCP connect)

pi0 avatar Nov 02 '24 07:11 pi0

I'm also interested in this. @fl0wo have you found any workaround in the meantime?

I'm partially migrating from AWS to CF, at least for the resources it make sense to migrate from.

And in doing this hybrid architecture, I'm trying to pushing some messages from CF Worker, to SQS (directly invoking the AWS API) (using the aws-lite library https://aws-lite.org/services/sqs)

In doing so, I get the https.request not implemented error.

Workaround 1: Ask aws-lite to allow me to implement a custom fetch (one that is compatible on CF env) Denied: https://github.com/aws-lite/aws-lite/issues/171

Workaround 2: Implement an ApiGtw on AWS, that wraps SQS, and simply pushes messages to SQS with a basic API-Key authentication. And I'll invoke that api endpoint from Cloudflare...

fl0wo avatar Nov 07 '24 09:11 fl0wo

(offtopic) @fl0wo have you tried aws4fetch as an alternative?

pi0 avatar Nov 07 '24 10:11 pi0

I can definitely recommend aws4fetch here:

  • It was created by Michael Hart who works at cf
  • It is used in @opennextjs/aws

vicb avatar Nov 07 '24 10:11 vicb

Relevant workerd discussion: https://github.com/cloudflare/workerd/discussions/3050

jasonbarry avatar Dec 02 '24 22:12 jasonbarry

aws4fetch

I followed your suggestion, it worked perfectly thank you.

fl0wo avatar Dec 25 '24 16:12 fl0wo

https.request and/or xmlhttprequest support would be great. I suspect many of the issues people are hitting are when an upstream dependency uses axios which uses either of these. Ideally we would just use fetch, but it's not often possible and a dealbreaker for people using workers

Edit - looks like Axios did add a fetch adapter recently - so that will probably alleviate these issues quite a bit. https://www.npmjs.com/package/axios#-fetch-adapter

wesbos avatar Feb 13 '25 14:02 wesbos

I guess cloudflare/workerd would be a good repo for that issue / discussion - there are probably existing ones

vicb avatar Feb 13 '25 15:02 vicb

Any update or workaround to this? This breaks many packages and makes it unusable on cloudflare / nuxthub

Specifically I was depending on a package for twitter-api-v2

xumx avatar Apr 09 '25 09:04 xumx

Major problem, tons of stuff broken, please fix

CoolOppo avatar Apr 10 '25 23:04 CoolOppo

For cloudflare users, this feature should be implemented in workerd (upstream tracker: https://github.com/cloudflare/workerd/issues/3820). You can check the native support coverage from here.

We might make a polyfill based on the new node:tls support, but I'm out of bandwidth right now also not sure if worth to invest time if it will be landing on workerd /cc @vicb @anonrig

pi0 avatar Apr 11 '25 07:04 pi0

We are unlikely to implement the node:https module directly in the runtime and will likely continue to rely on the unenv polyfills to bring these in. An implementation of node:https could likely fit on top of the built-in fetch implementation but it is also unlikely that we will ever fully support all of the TLS configuration options, lifecycle events, etc as our internal infrastructure uses an entirely different model than Node.js.

Originally posted by @jasnell in https://github.com/cloudflare/workerd/discussions/3050#discussioncomment-11152738

xumx avatar Apr 14 '25 03:04 xumx

I discovered this issue when migrating from pages to a worker, and the new vite/cloudflare plugin. What surprised me was that code that depended on https ran fine in pages. I thought pages was just an opinionated framework built on top of workers, but now I'm not so sure. Any idea why https worked in pages but not worker?

bunnybones1 avatar Apr 14 '25 05:04 bunnybones1

Yes, I really need this feature

Camusama avatar Apr 27 '25 18:04 Camusama

Would love this feature

reggieross avatar May 07 '25 16:05 reggieross

Sorry, just saw this https://github.com/cloudflare/workerd/issues/3820#issuecomment-3197578467

homerjam avatar Aug 26 '25 16:08 homerjam