#fsd
7 messages · Page 1 of 1 (latest)
Hi @spring tapir. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
You can add additional HTTP routes by calling http.route(...) on the same HttpRouter instance before exporting it.
For example:
// convex/http.ts
import { httpRouter } from "convex/server";
import { httpAction } from "./_generated/server";
import { authKit } from "@/convex/auth";
const http = httpRouter();
// Register WorkOS AuthKit routes
authKit.registerRoutes(http);
// Add your own routes
http.route({
path: "/hello",
method: "GET",
handler: httpAction(async (ctx, request) => {
return new Response("Hello from Convex!");
}),
});
// You can add more routes here in the same way
export default http;
This follows the standard pattern for defining HTTP actions and routes in convex/http.ts. [HTTP actions; WorkOS routes]
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@spring tapir Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kind zodiac what if i want to write the implementation for that http somewhere else
Let me check the knowledge base for you again. One moment! :books:
You can define the HTTP action in another file and just import it into convex/http.ts.
For example, put the implementation in convex/myHttpActions.ts:
// convex/myHttpActions.ts
import { httpAction } from "./_generated/server";
export const hello = httpAction(async (ctx, request) => {
return new Response("Hello from Convex!");
});
Then wire it up in convex/http.ts:
// convex/http.ts
import { httpRouter } from "convex/server";
import { authKit } from "@/convex/auth";
import { hello } from "./myHttpActions";
const http = httpRouter();
authKit.registerRoutes(http);
http.route({
path: "/hello",
method: "GET",
handler: hello,
});
export default http;