To configure CORS on your self-hosted Convex instance (including when running inside Coolify), you need to add the appropriate CORS headers in your HTTP actions. Convex does not automatically handle CORS for self-hosted deployments, so you must do this manually in your convex/http.ts file.
Here’s a standard pattern from the Convex documentation:
import { httpRouter } from "convex/server";
import { httpAction } from "./_generated/server";
const http = httpRouter();
http.route({
path: "/your-endpoint",
method: "POST",
handler: httpAction(async (ctx, request) => {
return new Response(null, {
status: 200,
headers: new Headers({
"Access-Control-Allow-Origin": process.env.CLIENT_ORIGIN!,
Vary: "origin",
}),
});
}),
});
http.route({
path: "/your-endpoint",
method: "OPTIONS",
handler: httpAction(async (_, request) => {
const headers = request.headers;
if (
headers.get("Origin") !== null &&
headers.get("Access-Control-Request-Method") !== null &&
headers.get("Access-Control-Request-Headers") !== null
) {
return new Response(null, {
headers: new Headers({
"Access-Control-Allow-Origin": process.env.CLIENT_ORIGIN!,
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Content-Type, Digest, Authorization",
"Access-Control-Max-Age": "86400",
}),
});
} else {
return new Response();
}
}),
});
export default http;