diff --git a/addons/api/addon/adapters/application.js b/addons/api/addon/adapters/application.js index a64f443bc..3fb95fda9 100644 --- a/addons/api/addon/adapters/application.js +++ b/addons/api/addon/adapters/application.js @@ -5,6 +5,13 @@ import { get } from '@ember/object'; export default class ApplicationAdapter extends RESTAdapter { // =attributes + /** + * Sets host to the `api.host` string in the application's config, + * if set. + * @type {string} + */ + host = get(config, 'api.host'); + /** * Sets namespace to the `api.namespace` string in the application's config, * if set. diff --git a/addons/api/tests/dummy/config/environment.js b/addons/api/tests/dummy/config/environment.js index b073014e3..914dad3be 100644 --- a/addons/api/tests/dummy/config/environment.js +++ b/addons/api/tests/dummy/config/environment.js @@ -23,7 +23,8 @@ module.exports = function (environment) { }, api: { - namespace: '/api/addon/v1', + host: '', + namespace: 'v1', }, }; diff --git a/ui/core/README.md b/ui/core/README.md index 84d20145c..5bfdb86b4 100644 --- a/ui/core/README.md +++ b/ui/core/README.md @@ -72,6 +72,7 @@ These environment variables may be used to customized the build. | Variable | Default Value | Description | | -------- | ------------- | ----------- | | `APP_NAME` | Application Name | The user-facing name of the application, appearing in titles, etc. | +| `API_HOST` | | The host of the API, if different than UI (e.g. https://example.net:1234). | ### Running Tests diff --git a/ui/core/config/environment.js b/ui/core/config/environment.js index 1f58b0d53..865c26a02 100644 --- a/ui/core/config/environment.js +++ b/ui/core/config/environment.js @@ -1,6 +1,7 @@ 'use strict'; const APP_NAME = process.env.APP_NAME || 'Application Name'; +const API_HOST = process.env.API_HOST || 'http://localhost:9200'; module.exports = function (environment) { let ENV = { @@ -26,6 +27,7 @@ module.exports = function (environment) { }, api: { + host: API_HOST, namespace: 'v1', }, @@ -71,6 +73,11 @@ module.exports = function (environment) { }; enableUnsafeCSP(); + // TODO: should provide an env var to explicitly add a host to CSP + // at build time for any environment (not just development), + // rather than automatically include API_HOST. Changes to CSP should + // be explicit. + if (API_HOST) ENV.contentSecurityPolicy['connect-src'].push(API_HOST); } if (environment === 'test') { diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index 7fae775bc..323eca350 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -21,5 +21,8 @@ export default function() { https://www.ember-cli-mirage.com/docs/route-handlers/shorthands */ + if (config.api.host) this.passthrough(`${config.api.host}/**`); + this.passthrough(); + this.get('/orgs/:org_id/projects'); }