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

Commit

Permalink
Attempt another unleash boot
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeofnorway committed Oct 7, 2023
1 parent 415f1c9 commit 521cf5d
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions src/server/api-handlers/features.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import { RequestHandler } from 'express';
import { startUnleash } from 'unleash-client';
import { startUnleash, initialize, Unleash } from 'unleash-client';

Check warning on line 2 in src/server/api-handlers/features.ts

View workflow job for this annotation

GitHub Actions / deploy

'startUnleash' is defined but never used

Check warning on line 2 in src/server/api-handlers/features.ts

View workflow job for this annotation

GitHub Actions / deploy / Build and deploy

'startUnleash' is defined but never used

let unleashInstance: Unleash;

const initializeUnleash = async () => {
const { UNLEASH_SERVER_API_TOKEN, UNLEASH_SERVER_API_URL } = process.env;
if (!UNLEASH_SERVER_API_TOKEN || !UNLEASH_SERVER_API_URL) {
return false;
}

unleashInstance = initialize({
url: UNLEASH_SERVER_API_URL,
appName: 'nav-dekoratoren',
customHeaders: { Authorization: UNLEASH_SERVER_API_TOKEN },
});

console.log(unleashInstance.isSynchronized() ? 'Unleash is synchronized' : 'Unleash is not synchronized');

return true;
};

export const getFeaturesHandler: RequestHandler = async (req, res) => {
// Cant easily fetch feature toggles when running locally
// so just mock this.
const { UNLEASH_SERVER_API_TOKEN, UNLEASH_SERVER_API_URL } = process.env;

if (!unleashInstance) {
initializeUnleash();
}

// res.status(500).send('Missing UNLEASH_SERVER_API_TOKEN or UNLEASH_SERVER_API_URL');

if (process.env.NODE_ENV === 'development') {
const features = {
Expand All @@ -15,24 +39,8 @@ export const getFeaturesHandler: RequestHandler = async (req, res) => {
return;
}

if (!UNLEASH_SERVER_API_TOKEN || !UNLEASH_SERVER_API_URL) {
res.status(500).send('Missing UNLEASH_SERVER_API_TOKEN or UNLEASH_SERVER_API_URL');
return;
}

try {
const unleash = await startUnleash({
url: UNLEASH_SERVER_API_URL,
appName: 'nav-dekoratoren',
customHeaders: { Authorization: UNLEASH_SERVER_API_TOKEN },
});

return {
skjermdeling: true,
chatbotscript: true,
};
} catch (e) {
console.error(`Failed to fetch feature toggles from unleash - ${e}`);
res.status(500).send(`Failed to fetch feature toggles from unleash - ${e}`);
}
return {
skjermdeling: true,
chatbotscript: true,
};
};

0 comments on commit 521cf5d

Please sign in to comment.