Skip to content

Commit 180b2f6

Browse files
committed
Move common code
1 parent ad3b41c commit 180b2f6

4 files changed

Lines changed: 34 additions & 43 deletions

File tree

packages/react-ui/src/app/constants/cloud.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const OPENOPS_CLOUD_URL = 'https://test.internal.openops.com';
1+
export const OPENOPS_CLOUD_URL = 'https://app.openops.com';
22
export const OPENOPS_CONNECT_TEMPLATES_URL = `${OPENOPS_CLOUD_URL}/connect`;
33
export const OPENOPS_CONNECT_TEMPLATES_LOGOUT_URL = `${OPENOPS_CLOUD_URL}/oauth/logout`;
44
export const OPENOPS_CONNECT_TEMPLATES_POLL_INTERVAL_MS = 800;

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +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 { allowAllOriginsHookHandler } from '../helper/allow-all-origins-hook-handler';
78
import { getVerifiedUser } from '../user-info/cloud-auth';
89
import { flowTemplateService } from './flow-template.service';
910

@@ -23,24 +24,7 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
2324
}
2425

2526
// cloud templates are available on any origin
26-
app.addHook('onSend', (request, reply, payload, done) => {
27-
void reply.header(
28-
'Access-Control-Allow-Origin',
29-
request.headers.origin || request.headers['Ops-Origin'] || '*',
30-
);
31-
void reply.header('Access-Control-Allow-Methods', 'GET,OPTIONS');
32-
void reply.header(
33-
'Access-Control-Allow-Headers',
34-
'Content-Type,Ops-Origin,Authorization',
35-
);
36-
void reply.header('Access-Control-Allow-Credentials', 'true');
37-
if (request.method === 'OPTIONS') {
38-
return reply.status(204).send();
39-
}
40-
41-
done(null, payload);
42-
return;
43-
});
27+
app.addHook('onSend', allowAllOriginsHookHandler);
4428

4529
app.get(
4630
'/',
@@ -67,8 +51,6 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
6751
async (request) => {
6852
const user = getVerifiedUser(request, publicKey);
6953
if (!user) {
70-
logger.info('User is not authenticated');
71-
7254
return flowTemplateService.getFlowTemplates({
7355
search: request.query.search,
7456
tags: request.query.tags,
@@ -84,8 +66,6 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
8466
});
8567
}
8668

87-
logger.info('User is authenticated');
88-
return [];
8969
return flowTemplateService.getFlowTemplates({
9070
search: request.query.search,
9171
tags: request.query.tags,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { onSendHookHandler } from 'fastify/types/hooks';
2+
3+
export const allowAllOriginsHookHandler: onSendHookHandler = (
4+
request,
5+
reply,
6+
payload,
7+
done,
8+
) => {
9+
void reply.header(
10+
'Access-Control-Allow-Origin',
11+
request.headers.origin || request.headers['Ops-Origin'] || '*',
12+
);
13+
14+
void reply.header('Access-Control-Allow-Methods', 'GET,OPTIONS');
15+
16+
void reply.header(
17+
'Access-Control-Allow-Headers',
18+
'Content-Type,Ops-Origin,Authorization',
19+
);
20+
21+
void reply.header('Access-Control-Allow-Credentials', 'true');
22+
23+
if (request.method === 'OPTIONS') {
24+
return reply.status(204).send();
25+
}
26+
27+
done(null, payload);
28+
return;
29+
};

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +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 { allowAllOriginsHookHandler } from '../helper/allow-all-origins-hook-handler';
45
import { getVerifiedUser } from './cloud-auth';
56

67
export const userInfoModule: FastifyPluginAsyncTypebox = async (app) => {
@@ -21,24 +22,7 @@ export const userInfoController: FastifyPluginAsyncTypebox = async (app) => {
2122
}
2223

2324
// user-info is available on any origin
24-
app.addHook('onSend', (request, reply, payload, done) => {
25-
void reply.header(
26-
'Access-Control-Allow-Origin',
27-
request.headers.origin || request.headers['Ops-Origin'] || '*',
28-
);
29-
void reply.header('Access-Control-Allow-Methods', 'GET,OPTIONS');
30-
void reply.header(
31-
'Access-Control-Allow-Headers',
32-
'Content-Type,Ops-Origin,Authorization',
33-
);
34-
void reply.header('Access-Control-Allow-Credentials', 'true');
35-
if (request.method === 'OPTIONS') {
36-
return reply.status(204).send();
37-
}
38-
39-
done(null, payload);
40-
return;
41-
});
25+
app.addHook('onSend', allowAllOriginsHookHandler);
4226

4327
app.get(
4428
'/',
@@ -52,11 +36,9 @@ export const userInfoController: FastifyPluginAsyncTypebox = async (app) => {
5236
const user = getVerifiedUser(request, publicKey);
5337

5438
if (!user) {
55-
logger.info('User is not authenticated');
5639
return reply.status(401).send();
5740
}
5841

59-
logger.info('User is authenticated');
6042
return user;
6143
},
6244
);

0 commit comments

Comments
 (0)