Skip to content

Commit e5e9636

Browse files
committed
Test
1 parent 7c0e20f commit e5e9636

4 files changed

Lines changed: 58 additions & 4 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
} from '@fastify/type-provider-typebox';
55
import { AppSystemProp, logger, system } from '@openops/server-shared';
66
import { ALL_PRINCIPAL_TYPES, OpenOpsId } from '@openops/shared';
7-
import { allowAllOriginsHookHandler } from '../helper/allow-all-origins-hook-handler';
7+
import {
8+
allowAllOriginsHookHandlerTest,
9+
} from '../helper/allow-all-origins-hook-handler';
810
import { getVerifiedUser } from '../user-info/cloud-auth';
911
import { flowTemplateService } from './flow-template.service';
1012

@@ -23,8 +25,20 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
2325
// return;
2426
// }
2527

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

2943
app.get(
3044
'/',

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { logger } from '@openops/server-shared';
2+
import { FastifyReply, FastifyRequest } from 'fastify';
23
import { onRequestHookHandler } from 'fastify/types/hooks';
34

45
export const allowAllOriginsHookHandler: onRequestHookHandler = (
@@ -27,3 +28,26 @@ export const allowAllOriginsHookHandler: onRequestHookHandler = (
2728

2829
done();
2930
};
31+
32+
export const allowAllOriginsHookHandlerTest = (
33+
request: FastifyRequest,
34+
reply: FastifyReply,
35+
) => {
36+
void reply.header(
37+
'Access-Control-Allow-Origin',
38+
request.headers.origin || request.headers['ops-origin'] || '*',
39+
);
40+
41+
void reply.header('Access-Control-Allow-Methods', 'GET,OPTIONS');
42+
43+
void reply.header(
44+
'Access-Control-Allow-Headers',
45+
'Content-Type,Ops-Origin,Authorization',
46+
);
47+
48+
void reply.header('Access-Control-Allow-Credentials', 'true');
49+
50+
logger.info('Returning 204 No Content for CORS preflight request.');
51+
52+
return reply.status(204).send();
53+
};

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
22
import { AppSystemProp, logger, system } from '@openops/server-shared';
33
import { ALL_PRINCIPAL_TYPES } from '@openops/shared';
4-
import { allowAllOriginsHookHandler } from '../helper/allow-all-origins-hook-handler';
4+
import {
5+
allowAllOriginsHookHandler,
6+
allowAllOriginsHookHandlerTest,
7+
} from '../helper/allow-all-origins-hook-handler';
58
import { getVerifiedUser } from './cloud-auth';
69

710
export const userInfoModule: FastifyPluginAsyncTypebox = async (app) => {
@@ -22,7 +25,19 @@ export const userInfoController: FastifyPluginAsyncTypebox = async (app) => {
2225
}
2326

2427
// user-info is available on any origin
25-
app.addHook('onRequest', allowAllOriginsHookHandler);
28+
// app.addHook('onRequest', allowAllOriginsHookHandler);
29+
30+
app.options(
31+
'/*',
32+
{
33+
config: {
34+
allowedPrincipals: ALL_PRINCIPAL_TYPES,
35+
skipAuth: true,
36+
cors: false,
37+
},
38+
},
39+
allowAllOriginsHookHandlerTest,
40+
);
2641

2742
app.get(
2843
'/',

packages/server/api/types/fastify.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ declare module 'fastify' {
2323
allowedPrincipals?: PrincipalType[];
2424
rawBody?: boolean;
2525
skipAuth?: boolean;
26+
cors?: boolean;
2627
scope?: EndpointScope;
2728
permission?: Permission;
2829
}

0 commit comments

Comments
 (0)