backend-app-api: readCorsOptions now disables cors by default

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-05 13:33:13 +01:00
parent 4097435eeb
commit e8d2de592d
2 changed files with 8 additions and 2 deletions
@@ -18,6 +18,12 @@ import { ConfigReader } from '@backstage/config';
import { readCorsOptions } from './readCorsOptions';
describe('readCorsOptions', () => {
it('should be disabled by default', () => {
expect(readCorsOptions(new ConfigReader({}))).toEqual({
origin: false,
});
});
it('reads single string', () => {
const mockCallback = jest.fn();
const config = new ConfigReader({ cors: { origin: 'https://*.value*' } });
@@ -29,10 +29,10 @@ import { Minimatch } from 'minimatch';
* const corsOptions = readCorsOptions(config.getConfig('backend'));
* ```
*/
export function readCorsOptions(config: Config): CorsOptions | undefined {
export function readCorsOptions(config: Config): CorsOptions {
const cc = config.getOptionalConfig('cors');
if (!cc) {
return undefined;
return { origin: false }; // Disable CORS
}
return {