Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
- KimHyeongRae0
- kirillgroshkov
- kkirsche
- kklem0
- kno-raziel
- knownasilya
- koojaa
Expand Down
42 changes: 42 additions & 0 deletions integration/react-router-serve-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,46 @@ test.describe("react-router-serve", () => {
});
});
}

test.describe("well-known URIs", () => {
for (const templateName of templateNames) {
test.describe(`template: ${templateName}`, () => {
let fixture: Fixture;
let appFixture: AppFixture;

test.beforeAll(async () => {
fixture = await createFixture({
templateName,
useReactRouterServe: true,
files: {
"public/.well-known/security.txt":
"Contact: mailto:security@example.com",
"public/.hidden.txt": "should not be served",
},
});
appFixture = await createAppFixture(fixture);
});

test.afterAll(() => {
appFixture.close();
});

test("serves files under /.well-known", async () => {
let response = await fetch(
`${appFixture.serverUrl}/.well-known/security.txt`,
);
expect(response.status).toBe(200);
expect(await response.text()).toContain(
"Contact: mailto:security@example.com",
);
});

test("keeps other dotfiles hidden", async () => {
let response = await fetch(`${appFixture.serverUrl}/.hidden.txt`);
expect(response.status).toBe(404);
expect(await response.text()).not.toContain("should not be served");
});
});
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Serve `/.well-known/*` files from the client build directory. Express 5's static middleware ignores every dot-segment path by default, so RFC 8615 well-known URIs — ACME challenges, Android's `assetlinks.json`, Apple's `apple-app-site-association` — fell through to the request handler and came back as app-rendered HTML instead of the static file. Other dotfiles remain hidden.
4 changes: 4 additions & 0 deletions packages/react-router-serve/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ async function run() {
);
app.use(expressPublicPath, express.static(build.assetsBuildDirectory));
app.use(express.static("public", { maxAge: "1h" }));
app.use(
"/.well-known",
express.static(path.join(build.assetsBuildDirectory, ".well-known")),
);
Comment thread
timdorr marked this conversation as resolved.
app.use(morgan("tiny"));

if (build.fetch) {
Expand Down
Loading