Skip to content

fix cors function for alpine linux#4091

Draft
khassel wants to merge 2 commits intoMagicMirrorOrg:developfrom
khassel:cors
Draft

fix cors function for alpine linux#4091
khassel wants to merge 2 commits intoMagicMirrorOrg:developfrom
khassel:cors

Conversation

@khassel
Copy link
Copy Markdown
Collaborator

@khassel khassel commented Apr 4, 2026

I provide docker images with alpine linux and tested the new cors approach.

It didn't work because after calling

  const dispatcher = new Agent({ connect: { lookup: (_h, _o, cb) => cb(null, address, family) } });

the dispatcher variable was undefined.

This PR solves this and I tested this under debian too.

The mix of internal fetch and newer undici did not work and alpine needs additionally the process.nextTick.

@khassel
Copy link
Copy Markdown
Collaborator Author

khassel commented Apr 4, 2026

to late to fix this now ...

@khassel khassel marked this pull request as draft April 4, 2026 22:57
@KristjanESPERANTO
Copy link
Copy Markdown
Collaborator

Yes, I had that problem with my previous PR and I think I have a solution. Can I add a commit?

@khassel
Copy link
Copy Markdown
Collaborator Author

khassel commented Apr 4, 2026

sure

@KristjanESPERANTO
Copy link
Copy Markdown
Collaborator

KristjanESPERANTO commented Apr 4, 2026

The problem was in the destructuring of undici while requiring it. In the production code const { fetch, Agent } = require("undici") copies the fetch function into a local variable. But in the test code vi.spyOn(undici, "fetch") replaces the property on the module object - so the production code holds its own copy and never sees the spy => tests failed (while production worked). Sounds simple, but it took me a few hours to figure that out for the last PR.

Ah, and on top of that, the spy was originally on global.fetch, which is an entirely different object than undici.fetch after the import change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants