mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-22 16:29:09 +01:00
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:
parent
2cbe023a38
commit
66bd8be2c9
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -278,5 +278,5 @@ jobs:
|
|||||||
run: npm install
|
run: npm install
|
||||||
|
|
||||||
- name: npm build
|
- name: npm build
|
||||||
run: npm run build:prod
|
run: npm run build:cloud
|
||||||
|
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,4 +12,4 @@ dist/
|
|||||||
*.swp
|
*.swp
|
||||||
build/
|
build/
|
||||||
!dev-server.shared.pem
|
!dev-server.shared.pem
|
||||||
config/development.json
|
config/local.json
|
||||||
|
11
README.md
11
README.md
@ -44,20 +44,23 @@ npm install
|
|||||||
ENV=production npm run build:watch
|
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",
|
"proxyApi": "http://your-api-url",
|
||||||
"proxyIdentity": "http://your-identity-url",
|
"proxyIdentity": "http://your-identity-url",
|
||||||
"proxyEvents": "http://your-events-url",
|
"proxyEvents": "http://your-events-url",
|
||||||
"proxyNotifications": "http://your-notifications-url",
|
"proxyNotifications": "http://your-notifications-url",
|
||||||
"proxyPortal": "http://your-portal-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
|
npm run build:dev:watch
|
||||||
|
37
config.js
37
config.js
@ -1,26 +1,29 @@
|
|||||||
function load(envName) {
|
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 {
|
return {
|
||||||
...baseConfig,
|
...require('./config/base.json'),
|
||||||
...overrideConfig
|
...loadConfig(envName),
|
||||||
|
...loadConfig('local'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(configObj) {
|
function log(configObj) {
|
||||||
const repeatNum = 50
|
const repeatNum = 50;
|
||||||
console.log(`${"=".repeat(repeatNum)}\nenvConfig`)
|
console.log(`${"=".repeat(repeatNum)}\nenvConfig`);
|
||||||
Object.entries(configObj).map(([key, value]) => {
|
console.log(JSON.stringify(configObj, null, 2));
|
||||||
console.log(` ${key}: ${value}`)
|
console.log(`${"=".repeat(repeatNum)}`);
|
||||||
})
|
}
|
||||||
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 = {
|
module.exports = {
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
{
|
{
|
||||||
"proxyApi": "http://localhost:4000",
|
"urls": {}
|
||||||
"proxyIdentity": "http://localhost:33656",
|
|
||||||
"proxyEvents": "http://localhost:46273",
|
|
||||||
"proxyNotifications": "http://localhost:61840",
|
|
||||||
"proxyPortal": "http://localhost:52313",
|
|
||||||
"allowedHosts": []
|
|
||||||
}
|
}
|
||||||
|
7
config/cloud.json
Normal file
7
config/cloud.json
Normal 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
11
config/development.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
@ -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"
|
|
||||||
}
|
|
@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"proxyApi": "https://api.qa.bitwarden.com",
|
"urls": {
|
||||||
"proxyIdentity": "https://identity.qa.bitwarden.com",
|
"icons": "https://icons.qa.bitwarden.pw",
|
||||||
"proxyEvents": "https://events.qa.bitwarden.com",
|
"notifications": "https://notifications.qa.bitwarden.pw",
|
||||||
"proxyNotifications": "https://notifications.qa.bitwarden.com",
|
"enterprise": "https://portal.qa.bitwarden.pw"
|
||||||
"proxyPortal": "https://portal.qa.bitwarden.com"
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
1
config/self-hosted.json
Normal file
1
config/self-hosted.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
19
package.json
19
package.json
@ -18,18 +18,15 @@
|
|||||||
"build:dev": "cross-env ENV=development npm run build",
|
"build:dev": "cross-env ENV=development npm run build",
|
||||||
"build:dev:watch": "cross-env ENV=development npm run build:watch",
|
"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": "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:cloud": "cross-env NODE_ENV=production ENV=cloud npm run build",
|
||||||
"build:prod": "cross-env NODE_ENV=production ENV=production npm run build",
|
"build:cloud:oss": "cross-env NODE_ENV=production ENV=cloud npm run build:oss",
|
||||||
"build:prod:oss": "cross-env NODE_ENV=production ENV=production npm run build:oss",
|
"build:selfhost": "cross-env ENV=selfhosted npm run build:watch",
|
||||||
"build:prod:watch": "cross-env NODE_ENV=production ENV=production npm run build:watch",
|
"build:selfhost:watch": "cross-env ENV=selfhosted npm run build:watch",
|
||||||
"build:selfhost": "cross-env SELF_HOST=true npm run build:watch",
|
"build:selfhost:prod": "cross-env ENV=selfhosted NODE_ENV=production npm run build",
|
||||||
"build:selfhost:watch": "cross-env SELF_HOST=true npm run build:watch",
|
"build:selfhost:prod:oss": "cross-env ENV=selfhosted NODE_ENV=production npm run build:oss",
|
||||||
"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",
|
|
||||||
"clean:l10n": "git push origin --delete l10n_master",
|
"clean:l10n": "git push origin --delete l10n_master",
|
||||||
"dist": "npm run build:prod && gulp postdist",
|
"dist": "npm run build:cloud && gulp postdist",
|
||||||
"dist:oss": "npm run build:prod:oss && gulp postdist",
|
"dist:oss": "npm run build:cloud:oss && gulp postdist",
|
||||||
"dist:selfhost": "npm run build:selfhost:prod && gulp postdist",
|
"dist:selfhost": "npm run build:selfhost:prod && gulp postdist",
|
||||||
"dist:selfhost:oss": "npm run build:selfhost:prod:oss && gulp postdist",
|
"dist:selfhost:oss": "npm run build:selfhost:prod:oss && gulp postdist",
|
||||||
"deploy": "npm run dist && gh-pages -d build",
|
"deploy": "npm run dist && gh-pages -d build",
|
||||||
|
@ -62,7 +62,7 @@ import { CipherService as CipherServiceAbstraction } from 'jslib-common/abstract
|
|||||||
import { CollectionService as CollectionServiceAbstraction } from 'jslib-common/abstractions/collection.service';
|
import { CollectionService as CollectionServiceAbstraction } from 'jslib-common/abstractions/collection.service';
|
||||||
import { CryptoService as CryptoServiceAbstraction } from 'jslib-common/abstractions/crypto.service';
|
import { CryptoService as CryptoServiceAbstraction } from 'jslib-common/abstractions/crypto.service';
|
||||||
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from 'jslib-common/abstractions/cryptoFunction.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 { EventService as EventLoggingServiceAbstraction } from 'jslib-common/abstractions/event.service';
|
||||||
import { ExportService as ExportServiceAbstraction } from 'jslib-common/abstractions/export.service';
|
import { ExportService as ExportServiceAbstraction } from 'jslib-common/abstractions/export.service';
|
||||||
import { FileUploadService as FileUploadServiceAbstraction } from 'jslib-common/abstractions/fileUpload.service';
|
import { FileUploadService as FileUploadServiceAbstraction } from 'jslib-common/abstractions/fileUpload.service';
|
||||||
@ -147,16 +147,9 @@ export function initFactory(): Function {
|
|||||||
return async () => {
|
return async () => {
|
||||||
await (storageService as HtmlStorageService).init();
|
await (storageService as HtmlStorageService).init();
|
||||||
|
|
||||||
if (process.env.ENV !== 'production' || platformUtilsService.isSelfHost()) {
|
const urls = process.env.URLS as Urls;
|
||||||
environmentService.setUrls({ base: window.location.origin }, false);
|
urls.base ??= window.location.origin;
|
||||||
} else {
|
environmentService.setUrls(urls, false);
|
||||||
environmentService.setUrls({
|
|
||||||
base: window.location.origin,
|
|
||||||
icons: 'https://icons.bitwarden.net',
|
|
||||||
notifications: 'https://notifications.bitwarden.com',
|
|
||||||
enterprise: 'https://portal.bitwarden.com',
|
|
||||||
}, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(() => notificationsService.init(), 3000);
|
setTimeout(() => notificationsService.init(), 3000);
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ export class AddCreditComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(private userService: UserService, private apiService: ApiService,
|
constructor(private userService: UserService, private apiService: ApiService,
|
||||||
private platformUtilsService: PlatformUtilsService) {
|
private platformUtilsService: PlatformUtilsService) {
|
||||||
if (process.env.ENV !== 'production' || platformUtilsService.isDev()) {
|
if (process.env.ENV !== 'cloud' || platformUtilsService.isDev()) {
|
||||||
this.ppButtonFormAction = WebConstants.paypal.buttonActionSandbox;
|
this.ppButtonFormAction = WebConstants.paypal.buttonActionSandbox;
|
||||||
this.ppButtonBusinessId = WebConstants.paypal.businessIdSandbox;
|
this.ppButtonBusinessId = WebConstants.paypal.businessIdSandbox;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ export class PaymentComponent implements OnInit {
|
|||||||
this.stripeScript.src = 'https://js.stripe.com/v3/';
|
this.stripeScript.src = 'https://js.stripe.com/v3/';
|
||||||
this.stripeScript.async = true;
|
this.stripeScript.async = true;
|
||||||
this.stripeScript.onload = () => {
|
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);
|
WebConstants.stripeLiveKey : WebConstants.stripeTestKey);
|
||||||
this.stripeElements = this.stripe.elements();
|
this.stripeElements = this.stripe.elements();
|
||||||
this.setStripeElement();
|
this.setStripeElement();
|
||||||
@ -126,7 +126,7 @@ export class PaymentComponent implements OnInit {
|
|||||||
if (this.method === PaymentMethodType.PayPal) {
|
if (this.method === PaymentMethodType.PayPal) {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
(window as any).braintree.dropin.create({
|
(window as any).braintree.dropin.create({
|
||||||
authorization: process.env.ENV === 'production' ?
|
authorization: process.env.ENV === 'cloud' ?
|
||||||
WebConstants.btProductionKey : WebConstants.btSandboxKey,
|
WebConstants.btProductionKey : WebConstants.btSandboxKey,
|
||||||
container: '#bt-dropin-container',
|
container: '#bt-dropin-container',
|
||||||
paymentOptionPriority: ['paypal'],
|
paymentOptionPriority: ['paypal'],
|
||||||
|
@ -253,7 +253,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isSelfHost(): boolean {
|
isSelfHost(): boolean {
|
||||||
return process.env.SELF_HOST.toString() === 'true';
|
return process.env.ENV.toString() === 'selfhosted';
|
||||||
}
|
}
|
||||||
|
|
||||||
copyToClipboard(text: string, options?: any): void | boolean {
|
copyToClipboard(text: string, options?: any): void | boolean {
|
||||||
|
@ -13,7 +13,7 @@ const config = require('./config.js');
|
|||||||
const ENV = process.env.ENV == null ? 'development' : process.env.ENV;
|
const ENV = process.env.ENV == null ? 'development' : process.env.ENV;
|
||||||
const NODE_ENV = process.env.NODE_ENV == null ? 'development' : process.env.NODE_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);
|
config.log(envConfig);
|
||||||
|
|
||||||
const moduleRules = [
|
const moduleRules = [
|
||||||
@ -141,9 +141,9 @@ const plugins = [
|
|||||||
new webpack.EnvironmentPlugin({
|
new webpack.EnvironmentPlugin({
|
||||||
'ENV': ENV,
|
'ENV': ENV,
|
||||||
'NODE_ENV': NODE_ENV === 'production' ? 'production' : 'development',
|
'NODE_ENV': NODE_ENV === 'production' ? 'production' : 'development',
|
||||||
'SELF_HOST': process.env.SELF_HOST === 'true' ? true : false,
|
|
||||||
'APPLICATION_VERSION': pjson.version,
|
'APPLICATION_VERSION': pjson.version,
|
||||||
'CACHE_TAG': Math.random().toString(36).substring(7),
|
'CACHE_TAG': Math.random().toString(36).substring(7),
|
||||||
|
'URLS': envConfig['urls'] ?? {},
|
||||||
}),
|
}),
|
||||||
new AngularCompilerPlugin({
|
new AngularCompilerPlugin({
|
||||||
tsConfigPath: 'tsconfig.json',
|
tsConfigPath: 'tsconfig.json',
|
||||||
@ -154,7 +154,7 @@ const plugins = [
|
|||||||
|
|
||||||
// ref: https://webpack.js.org/configuration/dev-server/#devserver
|
// ref: https://webpack.js.org/configuration/dev-server/#devserver
|
||||||
let certSuffix = fs.existsSync('dev-server.local.pem') ? '.local' : '.shared';
|
let certSuffix = fs.existsSync('dev-server.local.pem') ? '.local' : '.shared';
|
||||||
const devServer = {
|
const devServer = ENV !== 'development' ? {} : {
|
||||||
https: {
|
https: {
|
||||||
key: fs.readFileSync('dev-server' + certSuffix + '.pem'),
|
key: fs.readFileSync('dev-server' + certSuffix + '.pem'),
|
||||||
cert: fs.readFileSync('dev-server' + certSuffix + '.pem'),
|
cert: fs.readFileSync('dev-server' + certSuffix + '.pem'),
|
||||||
@ -186,7 +186,7 @@ const devServer = {
|
|||||||
changeOrigin: true
|
changeOrigin: true
|
||||||
},
|
},
|
||||||
'/portal': {
|
'/portal': {
|
||||||
target: envConfig['proxyPortal'],
|
target: envConfig['proxyEnterprise'],
|
||||||
pathRewrite: {'^/portal' : ''},
|
pathRewrite: {'^/portal' : ''},
|
||||||
secure: false,
|
secure: false,
|
||||||
changeOrigin: true
|
changeOrigin: true
|
||||||
|
Loading…
Reference in New Issue
Block a user