Skip to content

Commit f3254ac

Browse files
thebenternclaude
andcommitted
Merge branch 'master' into v2
Brings the upstream device registry and CORS fixes into the v2 branch: - Seeed Wio Tracker L2 Pro (hwModel 137, esp32-s3, 16MB) added to the device hardware registry -- 114 devices to 115. - src/index.ts returns "" instead of throwing for a disallowed CORS origin, which had been turning every non-whitelisted request into a 500. Affects only the legacy tinyhttp server; the Worker path uses the static wildcard in worker/src/cors.ts and was never exposed to it. One adaptation was required. tests/worker/router.test.ts asserted the deviceHardware payload was exactly 38536 bytes, so the new entry broke the four "serves the same bytes" cases. That test is about the router resolving all four path spellings to one handler -- the byte count was incidental, and would break again on every future device addition. It now compares against DEVICE_HARDWARE.body from the generated module, which checks the actual bytes rather than just their count. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2 parents a5d7410 + c1a9608 commit f3254ac

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ app
5353
if (whitelist.indexOf(req.headers.origin) !== -1) {
5454
return req.headers.origin;
5555
}
56-
throw new Error("Origin not allowed by CORS");
56+
57+
// Not allowed: return no origin rather than throwing. @tinyhttp/cors
58+
// passes this return value straight to res.setHeader and does not catch,
59+
// so throwing here escaped the middleware and turned every request from a
60+
// non-whitelisted origin into a 500 -- including the OPTIONS preflight.
61+
// An empty value is the same denial the no-origin branch above already
62+
// returns: the browser sees no matching Access-Control-Allow-Origin and
63+
// blocks the read, which is where that decision belongs. Credentials are
64+
// enabled, so a wildcard is not an option.
65+
return "";
5766
},
5867
}),
5968
)

src/lib/resource.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,4 +1381,16 @@ export const deviceHardwareList: DeviceHardware[] = [
13811381
images: ["rak3401.svg"],
13821382
requiresDfu: true,
13831383
},
1384+
{
1385+
hwModel: 137,
1386+
hwModelSlug: "SEEED_WIO_TRACKER_L2",
1387+
platformioTarget: "seeed-wio-tracker-l2",
1388+
architecture: "esp32-s3",
1389+
activelySupported: false,
1390+
supportLevel: 1,
1391+
displayName: "Seeed Wio Tracker L2 Pro",
1392+
tags: ["Seeed"],
1393+
requiresDfu: true,
1394+
partitionScheme: "16MB",
1395+
},
13841396
];

tests/worker/router.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
waitOnExecutionContext,
55
} from "cloudflare:test";
66
import { beforeAll, describe, expect, it } from "vitest";
7+
import { DEVICE_HARDWARE } from "../../worker/src/generated/documents.js";
78
import worker from "../../worker/src/index.js";
89
import { FLASH_TTL } from "../../worker/src/respond.js";
910
import { seed } from "./seed.js";
@@ -31,7 +32,10 @@ describe("path matching reproduces regexparam", () => {
3132
])("%s serves the same bytes", async (p) => {
3233
const res = await call(p);
3334
expect(res.status).toBe(200);
34-
expect((await res.text()).length).toBe(38536);
35+
// Compare against the generated document rather than a hard-coded length: this test is
36+
// about the router resolving all four spellings to one handler, and a byte count turns
37+
// every device-registry addition into an unrelated failure here.
38+
expect(await res.text()).toBe(DEVICE_HARDWARE.body);
3539
});
3640

3741
it.each(["//resource/deviceHardware", "/resource//deviceHardware"])(

0 commit comments

Comments
 (0)