Skip to content

Commit 39b52c5

Browse files
thomasballingerConvex, Inc.
authored andcommitted
Reserve top-level .files http route (#39281)
This might be used for files in the future in order to move file hosting to the HTTP router domain. GitOrigin-RevId: 208123e0ec4ef2b7e00253003cefd0ce8d282a23
1 parent 4eaf373 commit 39b52c5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

npm-packages/convex/src/server/router.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ test("HttpRouter", () => {
5858
});
5959
}).toThrow();
6060

61+
expect(() => {
62+
http.route({ pathPrefix: "/.files/", method: "GET", handler: action1 });
63+
}).toThrow("pathPrefix '/.files/' is reserved");
64+
expect(() => {
65+
http.route({ path: "/.files", method: "GET", handler: action1 });
66+
}).toThrow("is reserved");
67+
expect(() => {
68+
http.route({ path: "/.files/", method: "GET", handler: action1 });
69+
}).toThrow("is reserved");
70+
expect(() => {
71+
http.route({ path: "/.files/foo/bar", method: "GET", handler: action1 });
72+
}).toThrow("is reserved");
73+
6174
expect(http.getRoutes()).toEqual([
6275
["/path1", "GET", action1],
6376
["/path1", "POST", action2],

npm-packages/convex/src/server/router.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ export class HttpRouter {
177177
if (!spec.path.startsWith("/")) {
178178
throw new Error(`path '${spec.path}' does not start with a /`);
179179
}
180+
if (spec.path.startsWith("/.files/") || spec.path === "/.files") {
181+
throw new Error(`path '${spec.path}' is reserved`);
182+
}
180183
const methods: Map<RoutableMethod, PublicHttpAction> =
181184
this.exactRoutes.has(spec.path)
182185
? this.exactRoutes.get(spec.path)!
@@ -197,6 +200,9 @@ export class HttpRouter {
197200
if (!spec.pathPrefix.endsWith("/")) {
198201
throw new Error(`pathPrefix ${spec.pathPrefix} must end with a /`);
199202
}
203+
if (spec.pathPrefix.startsWith("/.files/")) {
204+
throw new Error(`pathPrefix '${spec.pathPrefix}' is reserved`);
205+
}
200206
const prefixes =
201207
this.prefixRoutes.get(method) || new Map<string, PublicHttpAction>();
202208
if (prefixes.has(spec.pathPrefix)) {

0 commit comments

Comments
 (0)