From c3bfc084c47f62a78abbc0c12a7153e1d8545092 Mon Sep 17 00:00:00 2001 From: "Sarachan, Brion D" Date: Tue, 13 Feb 2018 13:31:17 -0500 Subject: [PATCH] Using gulp to set the value of Rt106_SERVER_URL from environment variable Rt106_SERVER_HOST. This eliminates the need to rebuild the Docker image to run on a different machine and not have the browser on localhost. --- package.json | 2 ++ public/config.js | 10 ++++------ public/config.json | 5 +++++ rt106-app/config.js | 10 ++++------ rt106-app/config.json | 4 ++++ rt106-server/rt106-server.js | 33 ++++++++++++++++++++++++++++++++- 6 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 public/config.json create mode 100644 rt106-app/config.json diff --git a/package.json b/package.json index cd5ad78..59773e9 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,8 @@ "csvtojson": "^1.1.4", "date-format": "0.0.2", "express": "^4.13.4", + "gulp": "^3.9.1", + "gulp-ng-constant": "^1.2.0", "mysql": "~2.11.1", "request": "^2.81.0", "request-promise": "^3.0.0", diff --git a/public/config.js b/public/config.js index 9f0e843..1fbe92e 100644 --- a/public/config.js +++ b/public/config.js @@ -1,9 +1,7 @@ -// Copyright (c) General Electric Company, 2017. All rights reserved. +angular.module("rt106.config", []) -angular.module('rt106.config', []) +.constant("API_VERSION", "v1") - .constant('API_VERSION', 'v1') +.constant("Rt106_SERVER_URL", "http://localhost") - .constant('Rt106_SERVER_URL', 'http://localhost') - -; +; \ No newline at end of file diff --git a/public/config.json b/public/config.json new file mode 100644 index 0000000..c76e412 --- /dev/null +++ b/public/config.json @@ -0,0 +1,5 @@ +{ + "API_VERSION": "v1", + "Rt106_SERVER_URL": "http://localhost" +} + diff --git a/rt106-app/config.js b/rt106-app/config.js index 9f0e843..b09c61d 100644 --- a/rt106-app/config.js +++ b/rt106-app/config.js @@ -1,9 +1,7 @@ -// Copyright (c) General Electric Company, 2017. All rights reserved. +angular.module("rt106.config", []) -angular.module('rt106.config', []) + .constant("API_VERSION", "v1") - .constant('API_VERSION', 'v1') + .constant("Rt106_SERVER_URL", "http://localhost") - .constant('Rt106_SERVER_URL', 'http://localhost') - -; +; \ No newline at end of file diff --git a/rt106-app/config.json b/rt106-app/config.json new file mode 100644 index 0000000..c7d6996 --- /dev/null +++ b/rt106-app/config.json @@ -0,0 +1,4 @@ +{ + "API_VERSION": "v1", + "Rt106_SERVER_URL": "http://localhost" +} diff --git a/rt106-server/rt106-server.js b/rt106-server/rt106-server.js index e283590..f8f5147 100644 --- a/rt106-server/rt106-server.js +++ b/rt106-server/rt106-server.js @@ -10,7 +10,6 @@ const request = require('request'); const csv = require('csvtojson'); //const cors = require('cors'); - const winston = require('winston'); // Rt 106 modules @@ -21,6 +20,38 @@ const healthMgr = require('./healthMgr'); // module for checking the health var AMQPmgr = null; // optional module for managing RabbitMQ queues. var SQSmgr = null; // optional module for managing SQS queues +/* + * Dynamically create the config.js file. + * If the environment variable Rt106_SERVER_HOST is defined, that is used in config.js. Otherwise localhost is used. + * If the environment variable Rt106_APP_DIR is defined, that is the location where config.js needs to be. Otherwise use rt106-app. + */ +var gulp = require('gulp'); +var ngConstant = require('gulp-ng-constant'); +var Rt106_SERVER_URL = 'http://localhost'; // Default value, may be changed below. +if (process.env.Rt106_SERVER_HOST !== undefined) { + Rt106_SERVER_URL = 'http://' + process.env.Rt106_SERVER_HOST; +} +console.log("gulp setting Rt106_SERVER_URL to " + Rt106_SERVER_URL); +var Rt106_APP_DIR = 'rt106-app'; +if (process.env.Rt106_SERVE_APP !== undefined) { + Rt106_APP_DIR = process.env.Rt106_SERVE_APP; +} +gulp.task('default', function() { + gulp.src(Rt106_APP_DIR + '/config.json') + .pipe(ngConstant({ + name: 'rt106.config', + constants: + { + Rt106_SERVER_URL: Rt106_SERVER_URL + } + })) + .pipe(gulp.dest(Rt106_APP_DIR)); +}); +gulp.start('default'); +/* + * End of dynamic creation of config.js. + */ + // Constants const PORT = 8106; //const filepath = '/tests/demo_data/'; // for "local" (testing) DICOM store.