From 35d6a28c948c07402fcaf85929ae14506b31b7ff Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Fri, 23 Jul 2021 20:03:14 +0200 Subject: [PATCH] Ensure Angular is running as production (#1093) --- bitwarden_license/src/app/main.ts | 2 +- src/app/main.ts | 2 +- src/app/polyfills.ts | 2 +- src/app/settings/add-credit.component.ts | 2 +- src/app/settings/payment.component.ts | 6 +++--- src/services/webPlatformUtils.service.ts | 2 +- webpack.config.js | 1 + 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bitwarden_license/src/app/main.ts b/bitwarden_license/src/app/main.ts index 9fe08649..075236e1 100644 --- a/bitwarden_license/src/app/main.ts +++ b/bitwarden_license/src/app/main.ts @@ -10,7 +10,7 @@ require('src/scss/styles.scss'); import { AppModule } from './app.module'; -if (process.env.ENV === 'production') { +if (process.env.NODE_ENV === 'production') { enableProdMode(); } diff --git a/src/app/main.ts b/src/app/main.ts index 24f4859b..658accad 100644 --- a/src/app/main.ts +++ b/src/app/main.ts @@ -10,7 +10,7 @@ require('../scss/styles.scss'); import { AppModule } from './app.module'; -if (process.env.ENV === 'production') { +if (process.env.NODE_ENV === 'production') { enableProdMode(); } diff --git a/src/app/polyfills.ts b/src/app/polyfills.ts index 8b02bb78..4f0c23a8 100644 --- a/src/app/polyfills.ts +++ b/src/app/polyfills.ts @@ -7,7 +7,7 @@ if (!Element.prototype.matches && (Element.prototype as any).msMatchesSelector) Element.prototype.matches = (Element.prototype as any).msMatchesSelector; } -if (process.env.ENV === 'production') { +if (process.env.NODE_ENV === 'production') { // Production } else { // Development and test diff --git a/src/app/settings/add-credit.component.ts b/src/app/settings/add-credit.component.ts index 1317ea02..919465a3 100644 --- a/src/app/settings/add-credit.component.ts +++ b/src/app/settings/add-credit.component.ts @@ -47,7 +47,7 @@ export class AddCreditComponent implements OnInit { constructor(private userService: UserService, private apiService: ApiService, private platformUtilsService: PlatformUtilsService) { - if (platformUtilsService.isDev()) { + if (process.env.ENV !== 'production' || platformUtilsService.isDev()) { this.ppButtonFormAction = WebConstants.paypal.buttonActionSandbox; this.ppButtonBusinessId = WebConstants.paypal.businessIdSandbox; } diff --git a/src/app/settings/payment.component.ts b/src/app/settings/payment.component.ts index 62a73893..b6203d59 100644 --- a/src/app/settings/payment.component.ts +++ b/src/app/settings/payment.component.ts @@ -67,7 +67,7 @@ export class PaymentComponent implements OnInit { this.stripeScript.src = 'https://js.stripe.com/v3/'; this.stripeScript.async = true; this.stripeScript.onload = () => { - this.stripe = (window as any).Stripe(process.env.ENV === 'production' ? + this.stripe = (window as any).Stripe(process.env.ENV === 'production' && !platformUtilsService.isDev() ? WebConstants.stripeLiveKey : WebConstants.stripeTestKey); this.stripeElements = this.stripe.elements(); this.setStripeElement(); @@ -126,8 +126,8 @@ export class PaymentComponent implements OnInit { if (this.method === PaymentMethodType.PayPal) { window.setTimeout(() => { (window as any).braintree.dropin.create({ - authorization: this.platformUtilsService.isDev() ? - WebConstants.btSandboxKey : WebConstants.btProductionKey, + authorization: process.env.ENV === 'production' ? + WebConstants.btProductionKey : WebConstants.btSandboxKey, container: '#bt-dropin-container', paymentOptionPriority: ['paypal'], paypal: { diff --git a/src/services/webPlatformUtils.service.ts b/src/services/webPlatformUtils.service.ts index e3aeea39..ecf00b26 100644 --- a/src/services/webPlatformUtils.service.ts +++ b/src/services/webPlatformUtils.service.ts @@ -249,7 +249,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService { } isDev(): boolean { - return process.env.ENV === 'development'; + return process.env.NODE_ENV === 'development'; } isSelfHost(): boolean { diff --git a/webpack.config.js b/webpack.config.js index 58a656d4..c3899731 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -135,6 +135,7 @@ const plugins = [ new webpack.DefinePlugin({ 'process.env': { 'ENV': JSON.stringify(ENV), + 'NODE_ENV': NODE_ENV === 'production' ? 'production' : 'development', 'SELF_HOST': JSON.stringify(process.env.SELF_HOST === 'true' ? true : false), 'APPLICATION_VERSION': JSON.stringify(pjson.version), 'CACHE_TAG': JSON.stringify(Math.random().toString(36).substring(7)),