Skip to content

Commit 0441c18

Browse files
committed
Test
1 parent e5e9636 commit 0441c18

3 files changed

Lines changed: 7 additions & 44 deletions

File tree

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ 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 {
8-
allowAllOriginsHookHandlerTest,
9-
} from '../helper/allow-all-origins-hook-handler';
7+
import { allowAllOriginsHookHandler } from '../helper/allow-all-origins-hook-handler';
108
import { getVerifiedUser } from '../user-info/cloud-auth';
119
import { flowTemplateService } from './flow-template.service';
1210

@@ -25,19 +23,17 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
2523
// return;
2624
// }
2725

28-
// app.addHook('onRequest', allowAllOriginsHookHandler);
29-
3026
// cloud templates are available on any origin
3127
app.options(
32-
'/*',
28+
'*',
3329
{
3430
config: {
3531
allowedPrincipals: ALL_PRINCIPAL_TYPES,
3632
skipAuth: true,
3733
cors: false,
3834
},
3935
},
40-
allowAllOriginsHookHandlerTest,
36+
allowAllOriginsHookHandler,
4137
);
4238

4339
app.get(

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

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,7 @@
11
import { logger } from '@openops/server-shared';
22
import { FastifyReply, FastifyRequest } from 'fastify';
3-
import { onRequestHookHandler } from 'fastify/types/hooks';
43

5-
export const allowAllOriginsHookHandler: onRequestHookHandler = (
6-
request,
7-
reply,
8-
done,
9-
) => {
10-
void reply.header(
11-
'Access-Control-Allow-Origin',
12-
request.headers.origin || request.headers['Ops-Origin'] || '*',
13-
);
14-
15-
void reply.header('Access-Control-Allow-Methods', 'GET,OPTIONS');
16-
17-
void reply.header(
18-
'Access-Control-Allow-Headers',
19-
'Content-Type,Ops-Origin,Authorization',
20-
);
21-
22-
void reply.header('Access-Control-Allow-Credentials', 'true');
23-
24-
if (request.method === 'OPTIONS') {
25-
logger.info('Hook returning 204 No Content for CORS preflight request.');
26-
return void reply.status(204).send();
27-
}
28-
29-
done();
30-
};
31-
32-
export const allowAllOriginsHookHandlerTest = (
4+
export const allowAllOriginsHookHandler = (
335
request: FastifyRequest,
346
reply: FastifyReply,
357
) => {

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
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 {
5-
allowAllOriginsHookHandler,
6-
allowAllOriginsHookHandlerTest,
7-
} from '../helper/allow-all-origins-hook-handler';
4+
import { allowAllOriginsHookHandler } from '../helper/allow-all-origins-hook-handler';
85
import { getVerifiedUser } from './cloud-auth';
96

107
export const userInfoModule: FastifyPluginAsyncTypebox = async (app) => {
@@ -25,18 +22,16 @@ export const userInfoController: FastifyPluginAsyncTypebox = async (app) => {
2522
}
2623

2724
// user-info is available on any origin
28-
// app.addHook('onRequest', allowAllOriginsHookHandler);
29-
3025
app.options(
31-
'/*',
26+
'*',
3227
{
3328
config: {
3429
allowedPrincipals: ALL_PRINCIPAL_TYPES,
3530
skipAuth: true,
3631
cors: false,
3732
},
3833
},
39-
allowAllOriginsHookHandlerTest,
34+
allowAllOriginsHookHandler,
4035
);
4136

4237
app.get(

0 commit comments

Comments
 (0)