Skip to content

Commit b34d7ca

Browse files
committed
Merge branch 'nakajimayoshi/main'
2 parents 746ec78 + ec5a78b commit b34d7ca

File tree

1 file changed

+10
-2
lines changed
  • packages/convex-helpers/server

1 file changed

+10
-2
lines changed

packages/convex-helpers/server/cors.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,22 @@ export type CorsConfig = {
8181
debug?: boolean;
8282
};
8383

84-
type RouteSpecWithCors = RouteSpec & CorsConfig;
84+
export type RouteSpecWithCors = RouteSpec & CorsConfig;
85+
86+
/**
87+
* An HttpRouter with built in cors support.
88+
*/
89+
export type CorsHttpRouter = {
90+
http: HttpRouter
91+
route: (routeSpec: RouteSpecWithCors) => void;
92+
};
8593

8694
/**
8795
* Factory function to create a router that adds CORS support to routes.
8896
* @param allowedOrigins An array of allowed origins for CORS.
8997
* @returns A function to use instead of http.route when you want CORS.
9098
*/
91-
export const corsRouter = (http: HttpRouter, corsConfig?: CorsConfig) => {
99+
export const corsRouter = (http: HttpRouter, corsConfig?: CorsConfig): CorsHttpRouter => {
92100
const allowedExactMethodsByPath: Map<string, Set<string>> = new Map();
93101
const allowedPrefixMethodsByPath: Map<string, Set<string>> = new Map();
94102
return {

0 commit comments

Comments
 (0)