@@ -7,6 +7,7 @@ const environment = process.env.SWITCHER_API_ENVIRONMENT;
77const domainName = process . env . SWITCHER_API_DOMAIN ;
88const url = process . env . SWITCHER_API_URL ;
99const logger = process . env . SWITCHER_API_LOGGER == 'true' ;
10+ const throttle = process . env . SWITCHER_API_THROTTLE ;
1011const certPath = process . env . SSL_CERT ;
1112const component = 'switcherapi' ;
1213
@@ -19,21 +20,23 @@ export const SwitcherKeys = Object.freeze({
1920
2021async function checkFeature ( feature , params ) {
2122 const switcher = Switcher . factory ( ) ;
22- return switcher . isItOn ( feature , params , true ) ;
23+
24+ if ( throttle ) {
25+ switcher . throttle ( throttle ) ;
26+ }
27+
28+ return switcher . detail ( ) . isItOn ( feature , params ) ;
2329}
2430
2531export async function getRateLimit ( key , component ) {
2632 if ( process . env . SWITCHER_API_ENABLE === 'true' && key !== process . env . SWITCHER_API_KEY ) {
2733 const domain = await getDomainById ( component . domain ) ;
28- const result = await checkFeature ( SwitcherKeys . RATE_LIMIT , [
34+ const response = await checkFeature ( SwitcherKeys . RATE_LIMIT , [
2935 checkValue ( String ( domain . owner ) )
3036 ] ) ;
3137
32- if ( result ) {
33- const log = Switcher . getLogger ( SwitcherKeys . RATE_LIMIT )
34- . find ( log => log . input [ 0 ] [ 1 ] === String ( domain . owner ) ) ;
35-
36- return JSON . parse ( log . response . message ) . rate_limit ;
38+ if ( response . result ) {
39+ return response . metadata . rate_limit ;
3740 }
3841 }
3942
0 commit comments