From 7eaa3b1a2bf72bd7e9de4d2619776d30397928e5 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Thu, 2 Jun 2016 15:31:21 +0200 Subject: [PATCH] Inject environment variables into app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injects environment variables into the app through webpack, rather than script snippets in index.html. As part of this: * Updated server.js to use node’s path package to resolve file paths * Ensure that all url environment variables passed to the app don’t have a trailing slash, allowing for cleaner template urls **Note**: There are still a number of constants that should be taken out of the app and put into environment variables. --- .env_template | 22 +++ .../further_details_fileuploader.js | 8 +- .../ascribe_forms/form_create_contract.js | 2 +- .../ascribe_forms/form_register_piece.js | 4 +- .../ascribe_forms/input_fineuploader.js | 4 +- js/components/ascribe_routes/proxy_handler.js | 7 +- .../contract_settings_update_button.js | 6 +- .../wallet/constants/wallet_api_urls.js | 26 ++-- .../constants/wallet_application_constants.js | 6 +- js/constants/api_urls.js | 136 +++++++++--------- js/history.js | 5 +- package.json | 1 + server.dev.js | 2 + server.js | 28 ++-- webpack.config.js | 18 +++ 15 files changed, 158 insertions(+), 117 deletions(-) diff --git a/.env_template b/.env_template index 8c4fe11c..aa8ed8ce 100644 --- a/.env_template +++ b/.env_template @@ -1,3 +1,25 @@ +# App settings +ONION_APP_VERSION= + +ONION_API_URL=http://localhost.com:8000/api +ONION_BASE_PATH= +ONION_SERVER_URL=http://localhost.com:8000 + +ONION_PORT=4000 + +# Raven settings +RAVEN_DSN_URL= + +# S3 settings +S3_ACCESS_KEY= + + +# Dev server configuration +ONION_DEV_HOST=localhost +ONION_DEV_PORT=3000 + + +# Integration testing SAUCE_USERNAME=ascribe SAUCE_ACCESS_KEY= SAUCE_DEFAULT_URL= diff --git a/js/components/ascribe_detail/further_details_fileuploader.js b/js/components/ascribe_detail/further_details_fileuploader.js index 681c8c8a..8f23e4e4 100644 --- a/js/components/ascribe_detail/further_details_fileuploader.js +++ b/js/components/ascribe_detail/further_details_fileuploader.js @@ -81,14 +81,14 @@ let FurtherDetailsFileuploader = React.createClass({ deleteFile={{ enabled: true, method: 'DELETE', - endpoint: AppConstants.serverUrl + 's3/delete', + endpoint: `${AppConstants.serverUrl}/s3/delete`, customHeaders: { 'X-CSRFToken': getCookie(AppConstants.csrftoken) } }} isReadyForFormSubmission={isReadyForFormSubmission} keyRoutine={{ - url: AppConstants.serverUrl + 's3/key/', + url: `${AppConstants.serverUrl}/s3/key/`, fileClass: 'otherdata', pieceId: pieceId }} @@ -96,7 +96,7 @@ let FurtherDetailsFileuploader = React.createClass({ onValidationFailed={onValidationFailed} setIsUploadReady={setIsUploadReady} session={{ - endpoint: AppConstants.serverUrl + 'api/blob/otherdatas/fineuploader_session/', + endpoint: `${AppConstants.serverUrl}/api/blob/otherdatas/fineuploader_session/`, customHeaders: { 'X-CSRFToken': getCookie(AppConstants.csrftoken) }, @@ -109,7 +109,7 @@ let FurtherDetailsFileuploader = React.createClass({ } }} signature={{ - endpoint: AppConstants.serverUrl + 's3/signature/', + endpoint: `${AppConstants.serverUrl}/s3/signature/`, customHeaders: { 'X-CSRFToken': getCookie(AppConstants.csrftoken) } diff --git a/js/components/ascribe_forms/form_create_contract.js b/js/components/ascribe_forms/form_create_contract.js index cbdd12c3..c19843d5 100644 --- a/js/components/ascribe_forms/form_create_contract.js +++ b/js/components/ascribe_forms/form_create_contract.js @@ -72,7 +72,7 @@ let CreateContractForm = React.createClass({ this.refs.digitalWorkFineUploader = ref} keyRoutine={{ - url: AppConstants.serverUrl + 's3/key/', + url: `${AppConstants.serverUrl}/s3/key/`, fileClass: 'digitalwork' }} createBlobRoutine={{ @@ -191,7 +191,7 @@ let RegisterPieceForm = React.createClass({ onValidationFailed={this.handleThumbnailValidationFailed} isReadyForFormSubmission={formSubmissionValidation.fileOptional} keyRoutine={{ - url: AppConstants.serverUrl + 's3/key/', + url: `${AppConstants.serverUrl}/s3/key/`, fileClass: 'thumbnail' }} validation={{ diff --git a/js/components/ascribe_forms/input_fineuploader.js b/js/components/ascribe_forms/input_fineuploader.js index 53afcac2..c62d9183 100644 --- a/js/components/ascribe_forms/input_fineuploader.js +++ b/js/components/ascribe_forms/input_fineuploader.js @@ -121,7 +121,7 @@ const InputFineUploader = React.createClass({ setWarning={setWarning} showErrorPrompt={showErrorPrompt} signature={{ - endpoint: AppConstants.serverUrl + 's3/signature/', + endpoint: `${AppConstants.serverUrl}/s3/signature/`, customHeaders: { 'X-CSRFToken': getCookie(AppConstants.csrftoken) } @@ -129,7 +129,7 @@ const InputFineUploader = React.createClass({ deleteFile={{ enabled: true, method: 'DELETE', - endpoint: AppConstants.serverUrl + 's3/delete', + endpoint: `${AppConstants.serverUrl}/s3/delete`, customHeaders: { 'X-CSRFToken': getCookie(AppConstants.csrftoken) } diff --git a/js/components/ascribe_routes/proxy_handler.js b/js/components/ascribe_routes/proxy_handler.js index 882fe65c..cfe64447 100644 --- a/js/components/ascribe_routes/proxy_handler.js +++ b/js/components/ascribe_routes/proxy_handler.js @@ -56,10 +56,11 @@ export function AuthRedirect({ to, when }) { * hence transitionTo cannot be used directly. * * While we're getting rid of `query.redirect` explicitly in the - * above `else if` statement, here it's sufficient to just call - * `baseUrl` + `redirectAuthenticated`, as it gets rid of queries as well. + * above `else if` statement, here it's sufficient to just set the + * location to `${baseUrl}/${redirectAuthenticated}`, as this will + * get rid of queries as well. */ - window.location = AppConstants.baseUrl + redirectAuthenticated; + window.location = `${AppConstants.baseUrl}/${redirectAuthenticated}`; return true; } diff --git a/js/components/ascribe_settings/contract_settings_update_button.js b/js/components/ascribe_settings/contract_settings_update_button.js index dc652b9b..73aa98ea 100644 --- a/js/components/ascribe_settings/contract_settings_update_button.js +++ b/js/components/ascribe_settings/contract_settings_update_button.js @@ -62,7 +62,7 @@ let ContractSettingsUpdateButton = React.createClass({ ref='fineuploader' fileInputElement={UploadButton({ showLabel: false })} keyRoutine={{ - url: AppConstants.serverUrl + 's3/key/', + url: `${AppConstants.serverUrl}/s3/key/`, fileClass: 'contract' }} createBlobRoutine={{ @@ -75,7 +75,7 @@ let ContractSettingsUpdateButton = React.createClass({ }} setIsUploadReady={() =>{/* So that ReactS3FineUploader is not complaining */}} signature={{ - endpoint: AppConstants.serverUrl + 's3/signature/', + endpoint: `${AppConstants.serverUrl}/s3/signature/`, customHeaders: { 'X-CSRFToken': getCookie(AppConstants.csrftoken) } @@ -83,7 +83,7 @@ let ContractSettingsUpdateButton = React.createClass({ deleteFile={{ enabled: true, method: 'DELETE', - endpoint: AppConstants.serverUrl + 's3/delete', + endpoint: `${AppConstants.serverUrl}/s3/delete`, customHeaders: { 'X-CSRFToken': getCookie(AppConstants.csrftoken) } diff --git a/js/components/whitelabel/wallet/constants/wallet_api_urls.js b/js/components/whitelabel/wallet/constants/wallet_api_urls.js index e381cc88..be332d6f 100644 --- a/js/components/whitelabel/wallet/constants/wallet_api_urls.js +++ b/js/components/whitelabel/wallet/constants/wallet_api_urls.js @@ -6,27 +6,27 @@ import walletConstants from './wallet_application_constants'; function getWalletApiUrls(subdomain) { if (subdomain === 'cyland') { return { - 'pieces_list': walletConstants.walletApiEndpoint + subdomain + '/pieces/', - 'piece': walletConstants.walletApiEndpoint + subdomain + '/pieces/${piece_id}/', - 'piece_extradata': walletConstants.walletApiEndpoint + subdomain + '/pieces/${piece_id}/extradata/', - 'user': walletConstants.walletApiEndpoint + subdomain + '/users/' + 'pieces_list': walletConstants.walletApiEndpoint + '/' + subdomain + '/pieces/', + 'piece': walletConstants.walletApiEndpoint + '/' + subdomain + '/pieces/${piece_id}/', + 'piece_extradata': walletConstants.walletApiEndpoint + '/' + subdomain + '/pieces/${piece_id}/extradata/', + 'user': walletConstants.walletApiEndpoint + '/' + subdomain + '/users/' }; } else if (subdomain === 'ikonotv') { return { - 'pieces_list': walletConstants.walletApiEndpoint + subdomain + '/pieces/', - 'piece': walletConstants.walletApiEndpoint + subdomain + '/pieces/${piece_id}/', - 'user': walletConstants.walletApiEndpoint + subdomain + '/users/' + 'pieces_list': walletConstants.walletApiEndpoint + '/' + subdomain + '/pieces/', + 'piece': walletConstants.walletApiEndpoint + '/' + subdomain + '/pieces/${piece_id}/', + 'user': walletConstants.walletApiEndpoint + '/' + subdomain + '/users/' }; } else if (subdomain === 'lumenus' || subdomain === '23vivi' || subdomain === 'polline' || subdomain === 'artcity' || subdomain === 'demo' || subdomain === 'liquidgallery') { return { - 'editions_list': walletConstants.walletApiEndpoint + 'markets/' + subdomain + '/pieces/${piece_id}/editions/', - 'edition': walletConstants.walletApiEndpoint + 'markets/' + subdomain + '/editions/${bitcoin_id}/', - 'pieces_list': walletConstants.walletApiEndpoint + 'markets/' + subdomain + '/pieces/', - 'piece': walletConstants.walletApiEndpoint + 'markets/' + subdomain + '/pieces/${piece_id}/', - 'piece_extradata': walletConstants.walletApiEndpoint + 'markets/' + subdomain + '/pieces/${piece_id}/extradata/', - 'user': walletConstants.walletApiEndpoint + 'markets/' + subdomain + '/users/' + 'editions_list': walletConstants.walletApiEndpoint + '/markets/' + subdomain + '/pieces/${piece_id}/editions/', + 'edition': walletConstants.walletApiEndpoint + '/markets/' + subdomain + '/editions/${bitcoin_id}/', + 'pieces_list': walletConstants.walletApiEndpoint + '/markets/' + subdomain + '/pieces/', + 'piece': walletConstants.walletApiEndpoint + '/markets/' + subdomain + '/pieces/${piece_id}/', + 'piece_extradata': walletConstants.walletApiEndpoint + '/markets/' + subdomain + '/pieces/${piece_id}/extradata/', + 'user': walletConstants.walletApiEndpoint + '/markets/' + subdomain + '/users/' }; } return {}; diff --git a/js/components/whitelabel/wallet/constants/wallet_application_constants.js b/js/components/whitelabel/wallet/constants/wallet_application_constants.js index cec456d9..c55744d3 100644 --- a/js/components/whitelabel/wallet/constants/wallet_application_constants.js +++ b/js/components/whitelabel/wallet/constants/wallet_application_constants.js @@ -2,8 +2,8 @@ import AppConstants from '../../../../constants/application_constants'; -let walletConstants = { - walletApiEndpoint: AppConstants.apiEndpoint + 'whitelabel/' +const walletConstants = { + walletApiEndpoint: `${AppConstants.apiEndpoint}/whitelabel` }; -export default walletConstants; \ No newline at end of file +export default walletConstants; diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js index 1690f431..79e7c83b 100644 --- a/js/constants/api_urls.js +++ b/js/constants/api_urls.js @@ -8,74 +8,74 @@ import { update } from '../utils/general_utils'; let ApiUrls = { - 'applications': AppConstants.apiEndpoint + 'applications/', - 'application_token_refresh': AppConstants.apiEndpoint + 'applications/refresh_token/', - 'blob_digitalworks': AppConstants.apiEndpoint + 'blob/digitalworks/', - 'blob_otherdatas': AppConstants.apiEndpoint + 'blob/otherdatas/', - 'blob_contracts': AppConstants.apiEndpoint + 'blob/contracts/', - 'blob_thumbnails': AppConstants.apiEndpoint + 'blob/thumbnails/', - 'coa': AppConstants.apiEndpoint + 'coa/${id}/', - 'coa_create': AppConstants.apiEndpoint + 'coa/', - 'coa_verify': AppConstants.apiEndpoint + 'coa/verify_coa/', - 'edition': AppConstants.apiEndpoint + 'editions/${bitcoin_id}/', - 'edition_delete': AppConstants.apiEndpoint + 'editions/${edition_id}/', - 'edition_remove_from_collection': AppConstants.apiEndpoint + 'ownership/shares/editions/${edition_id}/', - 'editions': AppConstants.apiEndpoint + 'editions/', // this should be moved to the one below - 'editions_list': AppConstants.apiEndpoint + 'pieces/${piece_id}/editions/', - 'licenses': AppConstants.apiEndpoint + 'ownership/licenses/', - 'note_private_edition': AppConstants.apiEndpoint + 'note/private/editions/', - 'note_private_piece': AppConstants.apiEndpoint + 'note/private/pieces/', - 'note_public_edition': AppConstants.apiEndpoint + 'note/public/editions/', - 'note_public_piece': AppConstants.apiEndpoint + 'note/public/pieces/', - 'notification_piecelist': AppConstants.apiEndpoint + 'notifications/pieces/', - 'notification_piece': AppConstants.apiEndpoint + 'notifications/pieces/${piece_id}/', - 'notification_editionlist': AppConstants.apiEndpoint + 'notifications/editions/', - 'notification_edition': AppConstants.apiEndpoint + 'notifications/editions/${edition_id}/', - 'notification_contractagreementlist': AppConstants.apiEndpoint + 'notifications/contract_agreements/', - 'ownership_contract_agreements': AppConstants.apiEndpoint + 'ownership/contract_agreements/', - 'ownership_contract_agreements_confirm': AppConstants.apiEndpoint + 'ownership/contract_agreements/${contract_agreement_id}/accept/', - 'ownership_contract_agreements_deny': AppConstants.apiEndpoint + 'ownership/contract_agreements/${contract_agreement_id}/reject/', - 'ownership_consigns': AppConstants.apiEndpoint + 'ownership/consigns/', - 'ownership_consigns_confirm': AppConstants.apiEndpoint + 'ownership/consigns/confirm/', - 'ownership_consigns_deny': AppConstants.apiEndpoint + 'ownership/consigns/deny/', - 'ownership_consigns_withdraw': AppConstants.apiEndpoint + 'ownership/consigns/withdraw/', - 'ownership_loans_pieces': AppConstants.apiEndpoint + 'ownership/loans/pieces/', - 'ownership_loans_pieces_confirm': AppConstants.apiEndpoint + 'ownership/loans/pieces/confirm/', - 'ownership_loans_pieces_deny': AppConstants.apiEndpoint + 'ownership/loans/pieces/deny/', - 'ownership_loans_pieces_request': AppConstants.apiEndpoint + 'ownership/loans/pieces/request/', - 'ownership_loans_pieces_request_confirm': AppConstants.apiEndpoint + 'ownership/loans/pieces/request_confirm/', - 'ownership_loans_pieces_request_deny': AppConstants.apiEndpoint + 'ownership/loans/pieces/request_deny/', - 'ownership_loans_editions': AppConstants.apiEndpoint + 'ownership/loans/editions/', - 'ownership_loans_confirm': AppConstants.apiEndpoint + 'ownership/loans/editions/confirm/', - 'ownership_loans_deny': AppConstants.apiEndpoint + 'ownership/loans/editions/deny/', - 'ownership_shares_editions': AppConstants.apiEndpoint + 'ownership/shares/editions/', - 'ownership_shares_pieces': AppConstants.apiEndpoint + 'ownership/shares/pieces/', - 'ownership_transfers': AppConstants.apiEndpoint + 'ownership/transfers/', - 'ownership_transfers_withdraw': AppConstants.apiEndpoint + 'ownership/transfers/withdraw/', - 'ownership_unconsigns': AppConstants.apiEndpoint + 'ownership/unconsigns/', - 'ownership_unconsigns_deny': AppConstants.apiEndpoint + 'ownership/unconsigns/deny/', - 'ownership_unconsigns_request': AppConstants.apiEndpoint + 'ownership/unconsigns/request/', - 'ownership_contract': AppConstants.apiEndpoint + 'ownership/contracts/${contract_id}/', - 'ownership_contract_list': AppConstants.apiEndpoint + 'ownership/contracts/', - 'piece': AppConstants.apiEndpoint + 'pieces/${piece_id}/', - 'piece_extradata': AppConstants.apiEndpoint + 'pieces/${piece_id}/extradata/', - 'pieces_list': AppConstants.apiEndpoint + 'pieces/', - 'piece_remove_from_collection': AppConstants.apiEndpoint + 'ownership/shares/pieces/${piece_id}/', - 'user': AppConstants.apiEndpoint + 'users/', - 'users_login': AppConstants.apiEndpoint + 'users/login/', - 'users_logout': AppConstants.apiEndpoint + 'users/logout/', - 'users_password_reset': AppConstants.apiEndpoint + 'users/reset_password/', - 'users_password_reset_request': AppConstants.apiEndpoint + 'users/request_reset_password/', - 'users_signup': AppConstants.apiEndpoint + 'users/', - 'users_username': AppConstants.apiEndpoint + 'users/username/', - 'users_profile': AppConstants.apiEndpoint + 'users/profile/', - 'wallet_settings': AppConstants.apiEndpoint + 'users/wallet_settings/', - 'webhook': AppConstants.apiEndpoint + 'webhooks/${webhook_id}/', - 'webhooks': AppConstants.apiEndpoint + 'webhooks/', - 'webhooks_events': AppConstants.apiEndpoint + 'webhooks/events/', - 'whitelabel_settings': AppConstants.apiEndpoint + 'whitelabel/settings/${subdomain}/', - 'delete_s3_file': AppConstants.serverUrl + 's3/delete/', - 'sign_url_s3': AppConstants.serverUrl + 's3/sign_url/' + 'applications': AppConstants.apiEndpoint + '/applications/', + 'application_token_refresh': AppConstants.apiEndpoint + '/applications/refresh_token/', + 'blob_digitalworks': AppConstants.apiEndpoint + '/blob/digitalworks/', + 'blob_otherdatas': AppConstants.apiEndpoint + '/blob/otherdatas/', + 'blob_contracts': AppConstants.apiEndpoint + '/blob/contracts/', + 'blob_thumbnails': AppConstants.apiEndpoint + '/blob/thumbnails/', + 'coa': AppConstants.apiEndpoint + '/coa/${id}/', + 'coa_create': AppConstants.apiEndpoint + '/coa/', + 'coa_verify': AppConstants.apiEndpoint + '/coa/verify_coa/', + 'edition': AppConstants.apiEndpoint + '/editions/${bitcoin_id}/', + 'edition_delete': AppConstants.apiEndpoint + '/editions/${edition_id}/', + 'edition_remove_from_collection': AppConstants.apiEndpoint + '/ownership/shares/editions/${edition_id}/', + 'editions': AppConstants.apiEndpoint + '/editions/', // this should be moved to the one below + 'editions_list': AppConstants.apiEndpoint + '/pieces/${piece_id}/editions/', + 'licenses': AppConstants.apiEndpoint + '/ownership/licenses/', + 'note_private_edition': AppConstants.apiEndpoint + '/note/private/editions/', + 'note_private_piece': AppConstants.apiEndpoint + '/note/private/pieces/', + 'note_public_edition': AppConstants.apiEndpoint + '/note/public/editions/', + 'note_public_piece': AppConstants.apiEndpoint + '/note/public/pieces/', + 'notification_piecelist': AppConstants.apiEndpoint + '/notifications/pieces/', + 'notification_piece': AppConstants.apiEndpoint + '/notifications/pieces/${piece_id}/', + 'notification_editionlist': AppConstants.apiEndpoint + '/notifications/editions/', + 'notification_edition': AppConstants.apiEndpoint + '/notifications/editions/${edition_id}/', + 'notification_contractagreementlist': AppConstants.apiEndpoint + '/notifications/contract_agreements/', + 'ownership_contract_agreements': AppConstants.apiEndpoint + '/ownership/contract_agreements/', + 'ownership_contract_agreements_confirm': AppConstants.apiEndpoint + '/ownership/contract_agreements/${contract_agreement_id}/accept/', + 'ownership_contract_agreements_deny': AppConstants.apiEndpoint + '/ownership/contract_agreements/${contract_agreement_id}/reject/', + 'ownership_consigns': AppConstants.apiEndpoint + '/ownership/consigns/', + 'ownership_consigns_confirm': AppConstants.apiEndpoint + '/ownership/consigns/confirm/', + 'ownership_consigns_deny': AppConstants.apiEndpoint + '/ownership/consigns/deny/', + 'ownership_consigns_withdraw': AppConstants.apiEndpoint + '/ownership/consigns/withdraw/', + 'ownership_loans_pieces': AppConstants.apiEndpoint + '/ownership/loans/pieces/', + 'ownership_loans_pieces_confirm': AppConstants.apiEndpoint + '/ownership/loans/pieces/confirm/', + 'ownership_loans_pieces_deny': AppConstants.apiEndpoint + '/ownership/loans/pieces/deny/', + 'ownership_loans_pieces_request': AppConstants.apiEndpoint + '/ownership/loans/pieces/request/', + 'ownership_loans_pieces_request_confirm': AppConstants.apiEndpoint + '/ownership/loans/pieces/request_confirm/', + 'ownership_loans_pieces_request_deny': AppConstants.apiEndpoint + '/ownership/loans/pieces/request_deny/', + 'ownership_loans_editions': AppConstants.apiEndpoint + '/ownership/loans/editions/', + 'ownership_loans_confirm': AppConstants.apiEndpoint + '/ownership/loans/editions/confirm/', + 'ownership_loans_deny': AppConstants.apiEndpoint + '/ownership/loans/editions/deny/', + 'ownership_shares_editions': AppConstants.apiEndpoint + '/ownership/shares/editions/', + 'ownership_shares_pieces': AppConstants.apiEndpoint + '/ownership/shares/pieces/', + 'ownership_transfers': AppConstants.apiEndpoint + '/ownership/transfers/', + 'ownership_transfers_withdraw': AppConstants.apiEndpoint + '/ownership/transfers/withdraw/', + 'ownership_unconsigns': AppConstants.apiEndpoint + '/ownership/unconsigns/', + 'ownership_unconsigns_deny': AppConstants.apiEndpoint + '/ownership/unconsigns/deny/', + 'ownership_unconsigns_request': AppConstants.apiEndpoint + '/ownership/unconsigns/request/', + 'ownership_contract': AppConstants.apiEndpoint + '/ownership/contracts/${contract_id}/', + 'ownership_contract_list': AppConstants.apiEndpoint + '/ownership/contracts/', + 'piece': AppConstants.apiEndpoint + '/pieces/${piece_id}/', + 'piece_extradata': AppConstants.apiEndpoint + '/pieces/${piece_id}/extradata/', + 'pieces_list': AppConstants.apiEndpoint + '/pieces/', + 'piece_remove_from_collection': AppConstants.apiEndpoint + '/ownership/shares/pieces/${piece_id}/', + 'user': AppConstants.apiEndpoint + '/users/', + 'users_login': AppConstants.apiEndpoint + '/users/login/', + 'users_logout': AppConstants.apiEndpoint + '/users/logout/', + 'users_password_reset': AppConstants.apiEndpoint + '/users/reset_password/', + 'users_password_reset_request': AppConstants.apiEndpoint + '/users/request_reset_password/', + 'users_signup': AppConstants.apiEndpoint + '/users/', + 'users_username': AppConstants.apiEndpoint + '/users/username/', + 'users_profile': AppConstants.apiEndpoint + '/users/profile/', + 'wallet_settings': AppConstants.apiEndpoint + '/users/wallet_settings/', + 'webhook': AppConstants.apiEndpoint + '/webhooks/${webhook_id}/', + 'webhooks': AppConstants.apiEndpoint + '/webhooks/', + 'webhooks_events': AppConstants.apiEndpoint + '/webhooks/events/', + 'whitelabel_settings': AppConstants.apiEndpoint + '/whitelabel/settings/${subdomain}/', + 'delete_s3_file': AppConstants.serverUrl + '/s3/delete/', + 'sign_url_s3': AppConstants.serverUrl + '/s3/sign_url/' }; diff --git a/js/history.js b/js/history.js index 3d0ecff5..9fcdd3ff 100644 --- a/js/history.js +++ b/js/history.js @@ -6,11 +6,8 @@ import createBrowserHistory from 'history/lib/createBrowserHistory'; import AppConstants from './constants/application_constants'; -// Remove the trailing slash if present -const baseUrl = AppConstants.baseUrl.replace(/\/$/, ''); - const history = useBasename(useQueries(createBrowserHistory))({ - basename: baseUrl + basename: AppConstants.baseUrl }); history.locationQueue = []; diff --git a/package.json b/package.json index 650a665d..8208d291 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,7 @@ "react-star-rating": "~1.3.2", "react-textarea-autosize": "^2.5.2", "react-transform-hmr": "^1.0.4", + "remove-trailing-slash": "^0.1.0", "resolve-url-loader": "^1.4.3", "sass-loader": "^3.2.0", "shallow-equals": "0.0.0", diff --git a/server.dev.js b/server.dev.js index 8da3ca22..73024dca 100644 --- a/server.dev.js +++ b/server.dev.js @@ -3,6 +3,7 @@ 'use strict'; const path = require('path'); +const removeTrailingSlash = require('remove-trailing-slash'); const WebpackDevServer = require('webpack-dev-server'); const webpack = require('webpack'); @@ -12,6 +13,7 @@ require('dotenv').load({ silent: true }); const HOST = process.env.ONION_DEV_HOST || 'localhost'; const PORT = process.env.ONION_DEV_PORT || 3000; +const BASE_PATH = removeTrailingSlash(process.env.ONION_BASE_PATH || '/'); // Enable server hot reloading // React hot reloading is enabled through .babelrc and babel-react-transform diff --git a/server.js b/server.js index 3cd54a27..276822aa 100644 --- a/server.js +++ b/server.js @@ -1,29 +1,29 @@ -var express = require('express'); -var compression = require('compression'); +const express = require('express'); +const compression = require('compression'); +const path = require('path'); +const removeTrailingSlash = require('remove-trailing-slash'); -var baseUrl = (function () { var baseUrl = process.env.ONION_BASE_URL || '/'; return baseUrl + (baseUrl.match(/\/$/) ? '' : '/'); })(); +const BASE_PATH = removeTrailingSlash(process.env.ONION_BASE_PATH || '/'); +const PORT = process.env.ONION_PORT || 4000; -var app = express(); +const app = express(); app.use(compression()); -app.use(baseUrl + 'static/js', express.static(__dirname + '/build/js')); -app.use(baseUrl + 'static/img', express.static(__dirname + '/build/img')); -app.use(baseUrl + 'static/css', express.static(__dirname + '/build/css')); -app.use(baseUrl + 'static/fonts', express.static(__dirname + '/build/fonts')); -app.use(baseUrl + 'static/thirdparty', express.static(__dirname + '/node_modules')); +app.use(path.join(BASE_PATH, '/static/js'), express.static(path.resolve(__dirname, 'dist/js'))); +app.use(path.join(BASE_PATH, '/static/css'), express.static(path.resolve(__dirname, 'dist/css'))); +app.use(path.join(BASE_PATH, '/static/fonts'), express.static(path.resolve(__dirname, 'dist/fonts'))); +app.use(path.join(BASE_PATH, '/static/third_party'), express.static(path.resolve(__dirname, 'dist/third_party'))); app.get(/.*/, function(req, res) { console.log('%s %s', req.method, req.path); - res.sendFile(__dirname + '/build/index.html'); + res.sendFile(path.resolve(__dirname, 'dist/index.html')); }); if (require.main === module) { - var port = process.env.PORT || 4000; - console.log('Starting Onion server on port', port, - 'baseUrl is set to', baseUrl); - app.listen(port); + console.log(`Starting Onion server on port ${PORT} with basePath set to ${BASE_PATH || '/'}`); + app.listen(PORT); } module.exports.app = app; diff --git a/webpack.config.js b/webpack.config.js index 5522ef8b..5ebb0600 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,6 +3,7 @@ 'use strict'; const path = require('path'); +const removeTrailingSlash = require('remove-trailing-slash'); const webpack = require('webpack'); const autoPrefixer = require('autoprefixer'); @@ -26,6 +27,23 @@ const PATHS = { const DEFINITIONS = { 'process.env': { NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'), + + APP_VERSION: JSON.stringify(process.env.ONION_APP_VERSION || 'dev'), + + API_URL: JSON.stringify( + removeTrailingSlash(process.env.ONION_API_URL || 'https://staging.ascribe.io/api') + ), + APP_BASE_PATH: JSON.stringify( + removeTrailingSlash(process.env.ONION_BASE_PATH || '') + ), + SERVER_URL: JSON.stringify( + removeTrailingSlash(process.env.ONION_SERVER_URL || 'https://staging.ascribe.io') + ), + + RAVEN_DSN_URL: JSON.stringify(process.env.RAVEN_DSN_URL || ''), + + S3_ACCESS_KEY: JSON.stringify(process.env.S3_ACCESS_KEY || ''), + }, };