Skip to content

fix cors function for alpine linux#4091

Merged
rejas merged 2 commits intoMagicMirrorOrg:developfrom
khassel:cors
Apr 5, 2026
Merged

fix cors function for alpine linux#4091
rejas merged 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.

@khassel khassel marked this pull request as ready for review April 5, 2026 07:11
@khassel
Copy link
Copy Markdown
Collaborator Author

khassel commented Apr 5, 2026

This should be merged by @rejas or @sdetweil, as Kristjan and I worked on it, thank you.

@rejas rejas merged commit 9b97add into MagicMirrorOrg:develop Apr 5, 2026
12 checks passed
@khassel khassel deleted the cors branch April 5, 2026 20:11
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.

3 participants