Skip to content

Commit 27957be

Browse files
Fix CORS for cloud templates routes (#1700)
Fixes OPS-3165 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Adjusted cross-origin handling so CORS headers are applied earlier in the request lifecycle. * OPTIONS (preflight) requests now return a 204 response without a payload, improving compatibility and reducing response overhead. * Result: more reliable cross-origin requests and slightly improved request handling performance. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 9825637 commit 27957be

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

packages/server/api/src/app/flow-template/cloud-template.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
2424
}
2525

2626
// cloud templates are available on any origin
27-
app.addHook('onSend', allowAllOriginsHookHandler);
27+
app.addHook('onRequest', allowAllOriginsHookHandler);
2828

2929
app.get(
3030
'/',

packages/server/api/src/app/helper/allow-all-origins-hook-handler.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { onSendHookHandler } from 'fastify/types/hooks';
1+
import { onRequestHookHandler } from 'fastify/types/hooks';
22

3-
export const allowAllOriginsHookHandler: onSendHookHandler = (
3+
export const allowAllOriginsHookHandler: onRequestHookHandler = (
44
request,
55
reply,
6-
payload,
76
done,
87
) => {
98
void reply.header(
@@ -21,9 +20,8 @@ export const allowAllOriginsHookHandler: onSendHookHandler = (
2120
void reply.header('Access-Control-Allow-Credentials', 'true');
2221

2322
if (request.method === 'OPTIONS') {
24-
return reply.status(204).send();
23+
return void reply.status(204).send();
2524
}
2625

27-
done(null, payload);
28-
return;
26+
done();
2927
};

packages/server/api/src/app/user-info/user-info.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const userInfoController: FastifyPluginAsyncTypebox = async (app) => {
2222
}
2323

2424
// user-info is available on any origin
25-
app.addHook('onSend', allowAllOriginsHookHandler);
25+
app.addHook('onRequest', allowAllOriginsHookHandler);
2626

2727
app.get(
2828
'/',

0 commit comments

Comments
 (0)