mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-19 20:51:35 +01:00
[SG-439] Add feature flags to web (#3092)
* Add feature flags to web * Remove extra file from dev
This commit is contained in:
parent
6a26223f93
commit
0465168919
@ -9,5 +9,6 @@
|
|||||||
"dev": {
|
"dev": {
|
||||||
"port": 8080,
|
"port": 8080,
|
||||||
"allowedHosts": "auto"
|
"allowedHosts": "auto"
|
||||||
}
|
},
|
||||||
|
"flags": {}
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,8 @@
|
|||||||
"proxyApi": "https://api.bitwarden.com",
|
"proxyApi": "https://api.bitwarden.com",
|
||||||
"proxyIdentity": "https://identity.bitwarden.com",
|
"proxyIdentity": "https://identity.bitwarden.com",
|
||||||
"proxyEvents": "https://events.bitwarden.com"
|
"proxyEvents": "https://events.bitwarden.com"
|
||||||
|
},
|
||||||
|
"flags": {
|
||||||
|
"showTrial": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,8 @@
|
|||||||
"proxyIdentity": "http://localhost:33656",
|
"proxyIdentity": "http://localhost:33656",
|
||||||
"proxyEvents": "http://localhost:46273",
|
"proxyEvents": "http://localhost:46273",
|
||||||
"proxyNotifications": "http://localhost:61840"
|
"proxyNotifications": "http://localhost:61840"
|
||||||
|
},
|
||||||
|
"flags": {
|
||||||
|
"showTrial": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,8 @@
|
|||||||
"proxyApi": "https://api.qa.bitwarden.pw",
|
"proxyApi": "https://api.qa.bitwarden.pw",
|
||||||
"proxyIdentity": "https://identity.qa.bitwarden.pw",
|
"proxyIdentity": "https://identity.qa.bitwarden.pw",
|
||||||
"proxyEvents": "https://events.qa.bitwarden.pw"
|
"proxyEvents": "https://events.qa.bitwarden.pw"
|
||||||
|
},
|
||||||
|
"flags": {
|
||||||
|
"showTrial": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,5 +5,8 @@
|
|||||||
"proxyEvents": "http://localhost:46274",
|
"proxyEvents": "http://localhost:46274",
|
||||||
"proxyNotifications": "http://localhost:61841",
|
"proxyNotifications": "http://localhost:61841",
|
||||||
"port": 8081
|
"port": 8081
|
||||||
|
},
|
||||||
|
"flags": {
|
||||||
|
"showTrial": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import { NgModule } from "@angular/core";
|
import { NgModule } from "@angular/core";
|
||||||
import { RouterModule, Routes } from "@angular/router";
|
import { Route, RouterModule, Routes } from "@angular/router";
|
||||||
|
|
||||||
import { AuthGuard } from "@bitwarden/angular/guards/auth.guard";
|
import { AuthGuard } from "@bitwarden/angular/guards/auth.guard";
|
||||||
import { LockGuard } from "@bitwarden/angular/guards/lock.guard";
|
import { LockGuard } from "@bitwarden/angular/guards/lock.guard";
|
||||||
import { UnauthGuard } from "@bitwarden/angular/guards/unauth.guard";
|
import { UnauthGuard } from "@bitwarden/angular/guards/unauth.guard";
|
||||||
|
|
||||||
|
import { flagEnabled, FlagName } from "../utils/flags";
|
||||||
|
|
||||||
import { AcceptEmergencyComponent } from "./accounts/accept-emergency.component";
|
import { AcceptEmergencyComponent } from "./accounts/accept-emergency.component";
|
||||||
import { AcceptOrganizationComponent } from "./accounts/accept-organization.component";
|
import { AcceptOrganizationComponent } from "./accounts/accept-organization.component";
|
||||||
import { HintComponent } from "./accounts/hint.component";
|
import { HintComponent } from "./accounts/hint.component";
|
||||||
@ -65,12 +67,12 @@ const routes: Routes = [
|
|||||||
canActivate: [UnauthGuard],
|
canActivate: [UnauthGuard],
|
||||||
data: { titleId: "createAccount" },
|
data: { titleId: "createAccount" },
|
||||||
},
|
},
|
||||||
{
|
buildFlaggedRoute("showTrial", {
|
||||||
path: "trial",
|
path: "trial",
|
||||||
component: TrialInitiationComponent,
|
component: TrialInitiationComponent,
|
||||||
canActivate: [UnauthGuard],
|
canActivate: [UnauthGuard],
|
||||||
data: { titleId: "startTrial" },
|
data: { titleId: "startTrial" },
|
||||||
},
|
}),
|
||||||
{
|
{
|
||||||
path: "sso",
|
path: "sso",
|
||||||
component: SsoComponent,
|
component: SsoComponent,
|
||||||
@ -258,3 +260,12 @@ const routes: Routes = [
|
|||||||
exports: [RouterModule],
|
exports: [RouterModule],
|
||||||
})
|
})
|
||||||
export class OssRoutingModule {}
|
export class OssRoutingModule {}
|
||||||
|
|
||||||
|
export function buildFlaggedRoute(flagName: FlagName, route: Route): Route {
|
||||||
|
return flagEnabled(flagName)
|
||||||
|
? route
|
||||||
|
: {
|
||||||
|
path: route.path,
|
||||||
|
redirectTo: "/",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
19
apps/web/src/utils/flags.ts
Normal file
19
apps/web/src/utils/flags.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
export type Flags = {
|
||||||
|
showTrial?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type FlagName = keyof Flags;
|
||||||
|
|
||||||
|
export function flagEnabled(flag: FlagName): boolean {
|
||||||
|
return flags()[flag] == null || flags()[flag];
|
||||||
|
}
|
||||||
|
|
||||||
|
function flags(): Flags {
|
||||||
|
const envFlags = process.env.FLAGS as string | Flags;
|
||||||
|
|
||||||
|
if (typeof envFlags === "string") {
|
||||||
|
return JSON.parse(envFlags) as Flags;
|
||||||
|
} else {
|
||||||
|
return envFlags as Flags;
|
||||||
|
}
|
||||||
|
}
|
@ -151,6 +151,7 @@ const plugins = [
|
|||||||
STRIPE_KEY: envConfig["stripeKey"] ?? "",
|
STRIPE_KEY: envConfig["stripeKey"] ?? "",
|
||||||
BRAINTREE_KEY: envConfig["braintreeKey"] ?? "",
|
BRAINTREE_KEY: envConfig["braintreeKey"] ?? "",
|
||||||
PAYPAL_CONFIG: envConfig["paypal"] ?? {},
|
PAYPAL_CONFIG: envConfig["paypal"] ?? {},
|
||||||
|
FLAGS: envConfig["flags"] ?? {},
|
||||||
}),
|
}),
|
||||||
new webpack.ProvidePlugin({
|
new webpack.ProvidePlugin({
|
||||||
process: "process/browser",
|
process: "process/browser",
|
||||||
|
Loading…
Reference in New Issue
Block a user