Skip to content

Commit eaefb24

Browse files
committed
fix: return not found for missing public assets
1 parent 49140db commit eaefb24

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { afterEach, describe, expect, test, vi } from "vitest";
2+
import { loader } from "./_ui.$";
3+
4+
describe("_ui.$ loader", () => {
5+
afterEach(() => {
6+
vi.restoreAllMocks();
7+
});
8+
9+
test("returns 404 for missing apple touch icons without cross-origin logging", async () => {
10+
const consoleInfo = vi.spyOn(console, "info").mockImplementation(() => {});
11+
const request = new Request(
12+
"https://p-project.apps.webstudio.is/apple-touch-icon-precomposed.png",
13+
{
14+
headers: {
15+
accept: "*/*",
16+
},
17+
}
18+
);
19+
20+
await expect(
21+
loader({
22+
request,
23+
params: {},
24+
context: {},
25+
})
26+
).rejects.toMatchObject({
27+
status: 404,
28+
});
29+
expect(consoleInfo).not.toHaveBeenCalled();
30+
});
31+
});

apps/builder/app/routes/_ui.$.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
66
export { ErrorBoundary } from "~/shared/error/error-boundary";
77

88
export const loader = async ({ request }: LoaderFunctionArgs) => {
9-
preventCrossOriginCookie(request);
10-
11-
// No data to protect with CSRF token
12-
139
const url = new URL(request.url);
1410

1511
// Redirecting asset files (e.g., .js, .css) to the dashboard should be avoided.
@@ -28,6 +24,10 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
2824
});
2925
}
3026

27+
preventCrossOriginCookie(request);
28+
29+
// No data to protect with CSRF token
30+
3131
const contentType = request.headers.get("Content-Type");
3232

3333
if (contentType?.includes("application/json")) {

0 commit comments

Comments
 (0)