Set urls from config file (#1151)

* Set environment URLs in webpack config.

* Provide non NULL dev server

* QA env uses the pq TLD

* Include icons in qa env

* Move base configs to develop.

local configurations should be done in the `./config/local.json` file.

* Fix config override loading to default to development

* Standardize url formatting

* Limit QA settings to those set in production

* Set self hosted in a config

* Specify cloud instead of production

Self hosted and cloud are both production environments.
The ENV setting is used to specify the env type while
NODE_ENV specifies whether development error handling and services.

* Update config instructions

* Remove invalid json

* Change env `production` references to `cloud`

* Fix formatting
This commit is contained in:
Matt Gibson 2021-08-25 14:15:31 -04:00 committed by GitHub
parent 2cbe023a38
commit 66bd8be2c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 75 additions and 71 deletions

View File

@ -278,5 +278,5 @@ jobs:
run: npm install
- name: npm build
run: npm run build:prod
run: npm run build:cloud

2
.gitignore vendored
View File

@ -12,4 +12,4 @@ dist/
*.swp
build/
!dev-server.shared.pem
config/development.json
config/local.json

View File

@ -44,20 +44,23 @@ npm install
ENV=production npm run build:watch
```
You can also manually adjusting your API endpoint settings by adding `config/development.json` overriding any of the values in `config/base.json`. For example:
You can also manually adjusting your API endpoint settings by adding `config/local.json` overriding any of the following values:
```typescript
```json
{
"proxyApi": "http://your-api-url",
"proxyIdentity": "http://your-identity-url",
"proxyEvents": "http://your-events-url",
"proxyNotifications": "http://your-notifications-url",
"proxyPortal": "http://your-portal-url",
"allowedHosts": ["hostnames-to-allow-in-webpack"]
"allowedHosts": ["hostnames-to-allow-in-webpack"],
"urls": {
}
}
```
To pick up the overrides in the newly created `config/development.json` file, run the app with:
Where the `urls` object is defined by the [Urls type in jslib](https://github.com/bitwarden/jslib/blob/master/common/src/abstractions/environment.service.ts). To pick up the overrides in the newly created `config/local.json` file, run the app with:
```
npm run build:dev:watch

View File

@ -1,26 +1,29 @@
function load(envName) {
const envOverrides = {
'production': () => require('./config/production.json'),
'qa': () => require('./config/qa.json'),
'development': () => require('./config/development.json'),
};
const baseConfig = require('./config/base.json');
const overrideConfig = envOverrides.hasOwnProperty(envName) ? envOverrides[envName]() : {};
return {
...baseConfig,
...overrideConfig
...require('./config/base.json'),
...loadConfig(envName),
...loadConfig('local'),
};
}
function log(configObj) {
const repeatNum = 50
console.log(`${"=".repeat(repeatNum)}\nenvConfig`)
Object.entries(configObj).map(([key, value]) => {
console.log(` ${key}: ${value}`)
})
console.log(`${"=".repeat(repeatNum)}`)
const repeatNum = 50;
console.log(`${"=".repeat(repeatNum)}\nenvConfig`);
console.log(JSON.stringify(configObj, null, 2));
console.log(`${"=".repeat(repeatNum)}`);
}
function loadConfig(configName) {
try {
return require(`./config/${configName}.json`);
} catch (e) {
if (e instanceof Error && e.code === "MODULE_NOT_FOUND") {
return {};
}
else {
throw e;
}
}
}
module.exports = {

View File

@ -1,8 +1,3 @@
{
"proxyApi": "http://localhost:4000",
"proxyIdentity": "http://localhost:33656",
"proxyEvents": "http://localhost:46273",
"proxyNotifications": "http://localhost:61840",
"proxyPortal": "http://localhost:52313",
"allowedHosts": []
"urls": {}
}

7
config/cloud.json Normal file
View File

@ -0,0 +1,7 @@
{
"urls": {
"icons": "https://icons.bitwarden.net",
"notifications": "https://notifications.bitwarden.com",
"enterprise": "https://portal.bitwarden.com"
}
}

11
config/development.json Normal file
View File

@ -0,0 +1,11 @@
{
"proxyApi": "http://localhost:4000",
"proxyIdentity": "http://localhost:33656",
"proxyEvents": "http://localhost:46273",
"proxyNotifications": "http://localhost:61840",
"proxyEnterprise": "http://localhost:52313",
"allowedHosts": [],
"urls": {
"enterprise": "http://localhost:52313"
}
}

View File

@ -1,7 +0,0 @@
{
"proxyApi": "https://api.bitwarden.com",
"proxyIdentity": "https://identity.bitwarden.com",
"proxyEvents": "https://events.bitwarden.com",
"proxyNotifications": "https://notifications.bitwarden.com",
"proxyPortal": "https://portal.bitwarden.com"
}

View File

@ -1,7 +1,8 @@
{
"proxyApi": "https://api.qa.bitwarden.com",
"proxyIdentity": "https://identity.qa.bitwarden.com",
"proxyEvents": "https://events.qa.bitwarden.com",
"proxyNotifications": "https://notifications.qa.bitwarden.com",
"proxyPortal": "https://portal.qa.bitwarden.com"
"urls": {
"icons": "https://icons.qa.bitwarden.pw",
"notifications": "https://notifications.qa.bitwarden.pw",
"enterprise": "https://portal.qa.bitwarden.pw"
}
}

1
config/self-hosted.json Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -18,18 +18,15 @@
"build:dev": "cross-env ENV=development npm run build",
"build:dev:watch": "cross-env ENV=development npm run build:watch",
"build:qa": "cross-env NODE_ENV=production ENV=qa npm run build",
"build:qa:watch": "cross-env NODE_ENV=production ENV=qa npm run build:watch",
"build:prod": "cross-env NODE_ENV=production ENV=production npm run build",
"build:prod:oss": "cross-env NODE_ENV=production ENV=production npm run build:oss",
"build:prod:watch": "cross-env NODE_ENV=production ENV=production npm run build:watch",
"build:selfhost": "cross-env SELF_HOST=true npm run build:watch",
"build:selfhost:watch": "cross-env SELF_HOST=true npm run build:watch",
"build:selfhost:prod": "cross-env SELF_HOST=true NODE_ENV=production npm run build",
"build:selfhost:prod:oss": "cross-env SELF_HOST=true NODE_ENV=production npm run build:oss",
"build:selfhost:prod:watch": "cross-env SELF_HOST=true NODE_ENV=production npm run build:watch",
"build:cloud": "cross-env NODE_ENV=production ENV=cloud npm run build",
"build:cloud:oss": "cross-env NODE_ENV=production ENV=cloud npm run build:oss",
"build:selfhost": "cross-env ENV=selfhosted npm run build:watch",
"build:selfhost:watch": "cross-env ENV=selfhosted npm run build:watch",
"build:selfhost:prod": "cross-env ENV=selfhosted NODE_ENV=production npm run build",
"build:selfhost:prod:oss": "cross-env ENV=selfhosted NODE_ENV=production npm run build:oss",
"clean:l10n": "git push origin --delete l10n_master",
"dist": "npm run build:prod && gulp postdist",
"dist:oss": "npm run build:prod:oss && gulp postdist",
"dist": "npm run build:cloud && gulp postdist",
"dist:oss": "npm run build:cloud:oss && gulp postdist",
"dist:selfhost": "npm run build:selfhost:prod && gulp postdist",
"dist:selfhost:oss": "npm run build:selfhost:prod:oss && gulp postdist",
"deploy": "npm run dist && gh-pages -d build",

View File

@ -62,7 +62,7 @@ import { CipherService as CipherServiceAbstraction } from 'jslib-common/abstract
import { CollectionService as CollectionServiceAbstraction } from 'jslib-common/abstractions/collection.service';
import { CryptoService as CryptoServiceAbstraction } from 'jslib-common/abstractions/crypto.service';
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from 'jslib-common/abstractions/cryptoFunction.service';
import { EnvironmentService as EnvironmentServiceAbstraction } from 'jslib-common/abstractions/environment.service';
import { EnvironmentService as EnvironmentServiceAbstraction, Urls } from 'jslib-common/abstractions/environment.service';
import { EventService as EventLoggingServiceAbstraction } from 'jslib-common/abstractions/event.service';
import { ExportService as ExportServiceAbstraction } from 'jslib-common/abstractions/export.service';
import { FileUploadService as FileUploadServiceAbstraction } from 'jslib-common/abstractions/fileUpload.service';
@ -147,16 +147,9 @@ export function initFactory(): Function {
return async () => {
await (storageService as HtmlStorageService).init();
if (process.env.ENV !== 'production' || platformUtilsService.isSelfHost()) {
environmentService.setUrls({ base: window.location.origin }, false);
} else {
environmentService.setUrls({
base: window.location.origin,
icons: 'https://icons.bitwarden.net',
notifications: 'https://notifications.bitwarden.com',
enterprise: 'https://portal.bitwarden.com',
}, false);
}
const urls = process.env.URLS as Urls;
urls.base ??= window.location.origin;
environmentService.setUrls(urls, false);
setTimeout(() => notificationsService.init(), 3000);

View File

@ -47,7 +47,7 @@ export class AddCreditComponent implements OnInit {
constructor(private userService: UserService, private apiService: ApiService,
private platformUtilsService: PlatformUtilsService) {
if (process.env.ENV !== 'production' || platformUtilsService.isDev()) {
if (process.env.ENV !== 'cloud' || platformUtilsService.isDev()) {
this.ppButtonFormAction = WebConstants.paypal.buttonActionSandbox;
this.ppButtonBusinessId = WebConstants.paypal.businessIdSandbox;
}

View File

@ -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' && !platformUtilsService.isDev() ?
this.stripe = (window as any).Stripe(process.env.ENV === 'cloud' && !platformUtilsService.isDev() ?
WebConstants.stripeLiveKey : WebConstants.stripeTestKey);
this.stripeElements = this.stripe.elements();
this.setStripeElement();
@ -126,7 +126,7 @@ export class PaymentComponent implements OnInit {
if (this.method === PaymentMethodType.PayPal) {
window.setTimeout(() => {
(window as any).braintree.dropin.create({
authorization: process.env.ENV === 'production' ?
authorization: process.env.ENV === 'cloud' ?
WebConstants.btProductionKey : WebConstants.btSandboxKey,
container: '#bt-dropin-container',
paymentOptionPriority: ['paypal'],

View File

@ -253,7 +253,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService {
}
isSelfHost(): boolean {
return process.env.SELF_HOST.toString() === 'true';
return process.env.ENV.toString() === 'selfhosted';
}
copyToClipboard(text: string, options?: any): void | boolean {

View File

@ -13,7 +13,7 @@ const config = require('./config.js');
const ENV = process.env.ENV == null ? 'development' : process.env.ENV;
const NODE_ENV = process.env.NODE_ENV == null ? 'development' : process.env.NODE_ENV;
const envConfig = config.load(process.env.ENV);
const envConfig = config.load(ENV);
config.log(envConfig);
const moduleRules = [
@ -141,9 +141,9 @@ const plugins = [
new webpack.EnvironmentPlugin({
'ENV': ENV,
'NODE_ENV': NODE_ENV === 'production' ? 'production' : 'development',
'SELF_HOST': process.env.SELF_HOST === 'true' ? true : false,
'APPLICATION_VERSION': pjson.version,
'CACHE_TAG': Math.random().toString(36).substring(7),
'URLS': envConfig['urls'] ?? {},
}),
new AngularCompilerPlugin({
tsConfigPath: 'tsconfig.json',
@ -154,7 +154,7 @@ const plugins = [
// ref: https://webpack.js.org/configuration/dev-server/#devserver
let certSuffix = fs.existsSync('dev-server.local.pem') ? '.local' : '.shared';
const devServer = {
const devServer = ENV !== 'development' ? {} : {
https: {
key: fs.readFileSync('dev-server' + certSuffix + '.pem'),
cert: fs.readFileSync('dev-server' + certSuffix + '.pem'),
@ -186,7 +186,7 @@ const devServer = {
changeOrigin: true
},
'/portal': {
target: envConfig['proxyPortal'],
target: envConfig['proxyEnterprise'],
pathRewrite: {'^/portal' : ''},
secure: false,
changeOrigin: true