1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-23 13:46:45 +02:00

fix: frontend API CORS

This commit is contained in:
kwasniew 2025-07-03 12:13:48 +02:00
parent 4dc73dd7f6
commit 22be63240d
No known key found for this signature in database
GPG Key ID: 43A7CBC24C119560
2 changed files with 1 additions and 9 deletions

View File

@ -103,10 +103,7 @@ export default async function getApp(
if (config.enableOAS && services.openApiService) { if (config.enableOAS && services.openApiService) {
services.openApiService.useDocs(app); services.openApiService.useDocs(app);
} }
// Support CORS preflight requests for the frontend endpoints. app.use(
// Preflight requests should not have Authorization headers,
// so this must be handled before the API token middleware.
app.options(
`${baseUriPath}/api/frontend*`, `${baseUriPath}/api/frontend*`,
corsOriginMiddleware(services, config), corsOriginMiddleware(services, config),
); );

View File

@ -19,7 +19,6 @@ import {
} from '../../openapi/index.js'; } from '../../openapi/index.js';
import type { Context } from 'unleash-client'; import type { Context } from 'unleash-client';
import { enrichContextWithIp } from './index.js'; import { enrichContextWithIp } from './index.js';
import { corsOriginMiddleware } from '../../middleware/index.js';
import NotImplementedError from '../../error/not-implemented-error.js'; import NotImplementedError from '../../error/not-implemented-error.js';
import rateLimit from 'express-rate-limit'; import rateLimit from 'express-rate-limit';
import { minutesToMilliseconds } from 'date-fns'; import { minutesToMilliseconds } from 'date-fns';
@ -65,10 +64,6 @@ export default class FrontendAPIController extends Controller {
functionName, functionName,
}); });
// Support CORS requests for the frontend endpoints.
// Preflight requests are handled in `app.ts`.
this.app.use(corsOriginMiddleware(services, config));
this.route({ this.route({
method: 'get', method: 'get',
path: '', path: '',