diff --git a/app/models/doi.js b/app/models/doi.js index 07ff6ae7f..977a80b10 100644 --- a/app/models/doi.js +++ b/app/models/doi.js @@ -212,11 +212,7 @@ export default Model.extend(Validations, { downloadCount: attr('number'), identifier: computed('doi', 'repository', function () { - if (ENV.API_URL == 'https://api.datacite.org') { - return 'https://doi.org/' + this.doi; - } else { - return 'https://handle.stage.datacite.org/' + this.doi; - } + return ENV.HANDLE_SERVER + '/' + this.doi; }), isDraft: equal('state', 'draft'), showCitation: reads('registered'), diff --git a/config/environment.js b/config/environment.js index 046809ece..955449c07 100644 --- a/config/environment.js +++ b/config/environment.js @@ -1,6 +1,10 @@ /* eslint-env node */ 'use strict'; +function normalizeURL(val) { + return val.trim().replace(/\/$/, ''); +} + module.exports = function (environment) { const pkg = require('../package.json'); @@ -74,7 +78,7 @@ module.exports = function (environment) { 'https://63201db022924202b697e03bc5e0d0ba@o239790.ingest.sentry.io/1420435', disablePerformance: true, - environment: fabricaDeployTarget || "stage" + environment: fabricaDeployTarget || 'stage' } }, 'ember-cli-string-helpers': { @@ -148,9 +152,10 @@ module.exports = function (environment) { // when it is created }, - MIN_PREFIXES_AVAILABLE: minPrefixesAvailable, + MIN_PREFIXES_AVAILABLE: minPrefixesAvailable, SHOW_N_PREFIXES: showNPrefixes, - MAX_MINT_FUTURE_OFFSET: maxMintFutureOffset + MAX_MINT_FUTURE_OFFSET: maxMintFutureOffset, + HANDLE_SERVER: ((typeof process.env.HANDLE_SERVER === 'undefined') || (process.env.HANDLE_SERVER == "")) ? 'https://handle.stage.datacite.org' : normalizeURL(process.env.HANDLE_SERVER) }; if (fabricaDeployTarget === 'stage') { @@ -158,6 +163,11 @@ module.exports = function (environment) { ENV.COOKIE_DOMAIN = '.stage.datacite.org'; } + if (fabricaDeployTarget === 'test') { + // add test-env-specific settings here + ENV.HANDLE_SERVER = ((typeof process.env.HANDLE_SERVER === 'undefined') || (process.env.HANDLE_SERVER == "")) ? 'https://handle.stage.datacite.org' : normalizeURL(process.env.HANDLE_SERVER); + } + if (fabricaDeployTarget === 'production') { ENV.SITE_TITLE = 'DataCite Fabrica'; ENV.API_URL = 'https://api.datacite.org'; @@ -169,6 +179,7 @@ module.exports = function (environment) { ENV.CDN_URL = 'https://assets.datacite.org'; ENV.HOME_URL = 'https://datacite.org'; ENV.COOKIE_DOMAIN = '.datacite.org'; + ENV.HANDLE_SERVER = ((typeof process.env.HANDLE_SERVER === 'undefined') || (process.env.HANDLE_SERVER == "")) ? 'https://doi.org' : normalizeURL(process.env.HANDLE_SERVER); } // Environment named 'test' here is the ember environment, not related to fabrica environments. diff --git a/dotenv.js b/dotenv.js index ef93bf6a6..be99773e8 100644 --- a/dotenv.js +++ b/dotenv.js @@ -29,7 +29,8 @@ module.exports = function () { 'ENABLE_DOI_ESTIMATE', 'MIN_PREFIXES_AVAILABLE', 'MAX_MINT_FUTURE_OFFSET', - 'SHOW_N_PREFIXES' + 'SHOW_N_PREFIXES', + 'HANDLE_SERVER' ], fastbootAllowedKeys: [ 'SITE_TITLE', @@ -60,7 +61,8 @@ module.exports = function () { 'ENABLE_DOI_ESTIMATE', 'MIN_PREFIXES_AVAILABLE', 'MAX_MINT_FUTURE_OFFSET', - 'SHOW_N_PREFIXES' + 'SHOW_N_PREFIXES', + 'HANDLE_SERVER' ], failOnMissingKey: false };