Skip to content

Commit c6e4b66

Browse files
committed
Test
1 parent b5f4a72 commit c6e4b66

3 files changed

Lines changed: 27 additions & 28 deletions

File tree

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ 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+
allowAllOriginsHookHandler,
9+
registerOptionsEndpoint,
10+
} from '../helper/allow-all-origins-hook-handler';
811
import { getVerifiedUser } from '../user-info/cloud-auth';
912
import { flowTemplateService } from './flow-template.service';
1013

@@ -26,18 +29,7 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
2629
// cloud templates are available on any origin
2730
app.addHook('onRequest', allowAllOriginsHookHandler);
2831

29-
app.options(
30-
'*',
31-
{
32-
config: {
33-
allowedPrincipals: ALL_PRINCIPAL_TYPES,
34-
skipAuth: true,
35-
},
36-
},
37-
(_request, reply) => {
38-
return reply.status(204).send();
39-
},
40-
);
32+
registerOptionsEndpoint(app);
4133

4234
app.get(
4335
'/',

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { onRequestHookHandler } from 'fastify';
1+
import { ALL_PRINCIPAL_TYPES } from '@openops/shared';
2+
import { FastifyInstance, onRequestHookHandler } from 'fastify';
23

34
export const allowAllOriginsHookHandler: onRequestHookHandler = (
45
request,
@@ -21,3 +22,18 @@ export const allowAllOriginsHookHandler: onRequestHookHandler = (
2122

2223
done();
2324
};
25+
26+
export function registerOptionsEndpoint(app: FastifyInstance) {
27+
app.options(
28+
'*',
29+
{
30+
config: {
31+
allowedPrincipals: ALL_PRINCIPAL_TYPES,
32+
skipAuth: true,
33+
},
34+
},
35+
(_request, reply) => {
36+
return reply.status(204).send();
37+
},
38+
);
39+
}

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

Lines changed: 5 additions & 14 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+
registerOptionsEndpoint,
7+
} from '../helper/allow-all-origins-hook-handler';
58
import { getVerifiedUser } from './cloud-auth';
69

710
export const userInfoModule: FastifyPluginAsyncTypebox = async (app) => {
@@ -23,19 +26,7 @@ export const userInfoController: FastifyPluginAsyncTypebox = async (app) => {
2326

2427
// user-info is available on any origin
2528
app.addHook('onRequest', allowAllOriginsHookHandler);
26-
27-
app.options(
28-
'*',
29-
{
30-
config: {
31-
allowedPrincipals: ALL_PRINCIPAL_TYPES,
32-
skipAuth: true,
33-
},
34-
},
35-
(_request, reply) => {
36-
return reply.status(204).send();
37-
},
38-
);
29+
registerOptionsEndpoint(app);
3930

4031
app.get(
4132
'/',

0 commit comments

Comments
 (0)