Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/lib/features/frontend-api/frontend-api-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,39 @@ test('frontend api service fetching features from global cache', async () => {
expect(features).toHaveLength(1);
expect(createdFrontendRepositoriesCount).toBe(1);
});

test('setFrontendCorsSettings updates cached frontend settings immediately', async () => {
let storedSettings: any = {
frontendApiOrigins: ['https://initial.example.com'],
};
const settingService = {
getWithDefault: async () => storedSettings,
insert: async (_key: string, value: any) => {
storedSettings = value;
},
};

const frontendApiService = new FrontendApiService(
{
getLogger: noLogger,
eventBus: new EventEmitter(),
frontendApiOrigins: [],
} as unknown as Config,
{ settingService } as any,
{} as any,
);

// Populate initial cache
const initial = await frontendApiService.getFrontendSettings(true);
expect(initial.frontendApiOrigins).toEqual(['https://initial.example.com']);

// Update CORS settings
await frontendApiService.setFrontendCorsSettings(
['https://updated.example.com'],
{ id: 1, username: 'test-user', ip: '127.0.0.1' },
);

// Cached settings should immediately reflect updated settings
const cached = await frontendApiService.getFrontendSettings(true);
expect(cached.frontendApiOrigins).toEqual(['https://updated.example.com']);
});
4 changes: 3 additions & 1 deletion src/lib/features/frontend-api/frontend-api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,14 @@ export class FrontendApiService {
throw new BadDataError(error);
}
const settings = (await this.getFrontendSettings(false)) || {};
const updatedSettings = { ...settings, frontendApiOrigins: value };
await this.services.settingService.insert(
frontendSettingsKey,
{ ...settings, frontendApiOrigins: value },
updatedSettings,
auditUser,
false,
);
this.cachedFrontendSettings = updatedSettings;
Comment thread
Tyagiquamar marked this conversation as resolved.
}

async fetchFrontendSettings(): Promise<FrontendSettings> {
Expand Down
Loading