Skip to content

Commit 25fe3a8

Browse files
committed
WIP
1 parent a619a57 commit 25fe3a8

2 files changed

Lines changed: 19 additions & 56 deletions

File tree

packages/server/api/src/app/app.ts

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -137,47 +137,32 @@ export const setupApp = async (
137137

138138
await app.register(rateLimitModule);
139139

140-
await app.register(async (app) => {
141-
app.addHook('preHandler', async (req, _reply) => {
142-
const bypassCorsPlugin =
143-
req.routeOptions.config?.bypassCorsPlugin ?? false;
144-
145-
if (bypassCorsPlugin) {
146-
// reply.header('X-CORS-SKIPPED', 'true');
147-
logger.info('Bypass Cors Plugin');
148-
149-
return;
140+
await app.register(cors, {
141+
origin: (origin, callback) => {
142+
if (origin === system.get(SharedSystemProp.FRONTEND_URL)) {
143+
return callback(null, true);
150144
}
151-
});
152145

153-
await app.register(cors, {
154-
origin: (origin, callback) => {
155-
logger.info('Allow cors request plugin');
146+
const allowedDomainsString = system.get(AppSystemProp.ALLOWED_DOMAINS);
156147

157-
if (origin === system.get(SharedSystemProp.FRONTEND_URL)) {
148+
if (allowedDomainsString) {
149+
if (allowedDomainsString === '*') {
158150
return callback(null, true);
159151
}
160152

161-
const allowedDomainsString = system.get(AppSystemProp.ALLOWED_DOMAINS);
153+
const allowedDomains = allowedDomainsString.split(',');
162154

163-
if (allowedDomainsString) {
164-
if (allowedDomainsString === '*') {
165-
return callback(null, true);
166-
}
167-
168-
const allowedDomains = allowedDomainsString.split(',');
169-
170-
if (allowedDomains.includes(origin as string)) {
171-
return callback(null, true);
172-
}
155+
if (allowedDomains.includes(origin as string)) {
156+
return callback(null, true);
173157
}
158+
}
174159

175-
return callback(null, false);
176-
},
177-
exposedHeaders: ['*'],
178-
methods: ['*'],
179-
credentials: true,
180-
});
160+
logger.info('Block cors request plugin');
161+
return callback(null, false);
162+
},
163+
exposedHeaders: ['*'],
164+
methods: ['*'],
165+
credentials: true,
181166
});
182167

183168
await app.register(fastifySocketIO, {

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

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,13 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
2626
// cloud templates are available on any origin
2727
app.addHook('onRequest', allowAllOriginsHookHandler);
2828

29-
app.options('/*', async (request, reply) => {
30-
logger.info('Options request');
31-
32-
void reply.header(
33-
'Access-Control-Allow-Origin',
34-
request.headers.origin || request.headers['Ops-Origin'] || '*',
35-
);
36-
37-
void reply.header('Access-Control-Allow-Methods', 'GET,OPTIONS');
38-
39-
void reply.header(
40-
'Access-Control-Allow-Headers',
41-
'Content-Type,Ops-Origin,Authorization',
42-
);
43-
44-
void reply.header('Access-Control-Allow-Credentials', 'false');
45-
46-
if (request.method === 'OPTIONS') {
47-
return void reply.status(204).send();
48-
}
49-
});
50-
5129
app.get(
5230
'/',
5331
{
5432
config: {
5533
allowedPrincipals: ALL_PRINCIPAL_TYPES,
56-
bypassCorsPlugin: true,
5734
skipAuth: true,
35+
cors: false,
5836
},
5937
schema: {
6038
tags: ['flow-templates'],
@@ -95,8 +73,8 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
9573
{
9674
config: {
9775
allowedPrincipals: ALL_PRINCIPAL_TYPES,
98-
bypassCorsPlugin: true,
9976
skipAuth: true,
77+
cors: false,
10078
},
10179
schema: {
10280
tags: ['flow-templates'],

0 commit comments

Comments
 (0)