Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Rydder i kode og bedre mocking av features
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeofnorway committed Oct 8, 2023
1 parent 16b71a4 commit 3e363d2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/server/api-handlers/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,27 @@ const initializeUnleash = async () => {
initializeUnleash();

export const getFeaturesHandler: RequestHandler = async (req, res) => {
// If for some reason the unleash instance is not initialized,
// make a new attempt.
if (!unleashInstance) {
await initializeUnleash();
}

const { query } = req;
if (!query?.feature) {
res.status(400).json({ error: 'Missing feature query parameters' });
return;
}
const requestedFeatures: string[] = forceArray(query.feature);
const requestedFeatures: string[] = forceArray(query.feature).filter((feature) => typeof feature === 'string');

// Cant easily fetch feature toggles when running locally
// so just mock this.
if (process.env.NODE_ENV === 'development') {
const features = {
'dekoratoren.skjermdeling': true,
'dekoratoren.chatbotscript': true,
};
res.json(features);
const mockFeatures = requestedFeatures.reduce((acc: Features, feature: string) => {
acc[feature] = true;
return acc;
}, {});
res.json(mockFeatures);
return;
}

Expand Down

0 comments on commit 3e363d2

Please sign in to comment.