Skip to content

Commit 9e6756c

Browse files
committed
Test
1 parent 0441c18 commit 9e6756c

3 files changed

Lines changed: 13 additions & 29 deletions

File tree

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

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

2626
// cloud templates are available on any origin
27-
app.options(
28-
'*',
29-
{
30-
config: {
31-
allowedPrincipals: ALL_PRINCIPAL_TYPES,
32-
skipAuth: true,
33-
cors: false,
34-
},
35-
},
36-
allowAllOriginsHookHandler,
37-
);
27+
app.addHook('onRequest', allowAllOriginsHookHandler);
3828

3929
app.get(
4030
'/',
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { logger } from '@openops/server-shared';
2-
import { FastifyReply, FastifyRequest } from 'fastify';
2+
import { onRequestHookHandler } from 'fastify';
33

4-
export const allowAllOriginsHookHandler = (
5-
request: FastifyRequest,
6-
reply: FastifyReply,
4+
export const allowAllOriginsHookHandler: onRequestHookHandler = (
5+
request,
6+
reply,
7+
done,
78
) => {
89
void reply.header(
910
'Access-Control-Allow-Origin',
10-
request.headers.origin || request.headers['ops-origin'] || '*',
11+
request.headers.origin || request.headers['Ops-Origin'] || '*',
1112
);
1213

1314
void reply.header('Access-Control-Allow-Methods', 'GET,OPTIONS');
@@ -19,7 +20,10 @@ export const allowAllOriginsHookHandler = (
1920

2021
void reply.header('Access-Control-Allow-Credentials', 'true');
2122

22-
logger.info('Returning 204 No Content for CORS preflight request.');
23+
if (request.method === 'OPTIONS') {
24+
logger.info('Returning 204 No Content for CORS preflight request.');
25+
return void reply.status(204).send();
26+
}
2327

24-
return reply.status(204).send();
28+
done();
2529
};

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

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

2424
// user-info is available on any origin
25-
app.options(
26-
'*',
27-
{
28-
config: {
29-
allowedPrincipals: ALL_PRINCIPAL_TYPES,
30-
skipAuth: true,
31-
cors: false,
32-
},
33-
},
34-
allowAllOriginsHookHandler,
35-
);
25+
app.addHook('onRequest', allowAllOriginsHookHandler);
3626

3727
app.get(
3828
'/',

0 commit comments

Comments
 (0)