chore: 🤖 add support for API_HOST build-time config
This commit is contained in:
5 files changed
+20
-1
No files matched your search
@@ -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.
|
||||
|
||||
@@ -23,7 +23,8 @@ module.exports = function (environment) {
|
||||
},
|
||||
|
||||
api: {
|
||||
namespace: '/api/addon/v1',
|
||||
host: '',
|
||||
namespace: 'v1',
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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') {
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
Reference in new issue
Block a user