Skip to content

Commit

Permalink
Merge pull request #105 from e-ucm/a2proxyfix
Browse files Browse the repository at this point in the history
Nice ;)
  • Loading branch information
gorco committed May 11, 2020
2 parents 8a32c98 + 09ca9c3 commit 47183d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
3 changes: 3 additions & 0 deletions app/config-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ exports.projectName = '{{projectName}}';
exports.myHost = '{{myHost}}';
exports.a2 = {
a2ApiPath: '{{a2ApiPath}}',
a2ProxyPath: '{{a2ProxyPath}}',
a2Protocol: '{{a2Protocol}}',
a2Prefix: '{{a2Prefix}}',
a2HomePage: '{{a2HomePage}}',
a2AdminUsername: '{{a2AdminUsername}}',
a2AdminPassword: '{{a2AdminPassword}}'
};
exports.basePath = '{{basePath}}';
exports.kibanaPrefix = '{{kibanaPrefix}}';
exports.maxSizeRequest = '{{maxSizeRequest}}';
23 changes: 12 additions & 11 deletions app/config-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function initFromEnv(conf, prefix, links) {
*/
var values = linkPort.split('://');
if (values.length === 2) {
conf[link + 'Protocol'] = values[0];
values = values[1].split(':');
if (values.length === 2) {
conf[link + 'Host'] = values[0];
Expand All @@ -89,11 +90,12 @@ function initFromEnv(conf, prefix, links) {
exports.defaultValues = {
projectName: 'Analytics Frontend',
companyName: 'e-UCM Research Group',
a2Protocol: 'http',
a2Host: 'localhost',
a2Port: '3000',
a2Prefix: 'afront',
a2HomePage: 'http://localhost:3000/',
a2ApiPath: 'http://localhost:3000/api/',
a2ApiPath: 'api/',
a2ProxyPath: 'api/proxy/',
a2AdminUsername: 'root',
kibanaPrefix: 'kibana',
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
Expand All @@ -118,11 +120,12 @@ exports.defaultValues = {
exports.testValues = {
projectName: 'Analytics Frontend (Test)',
companyName: 'e-UCM Research Group (Test)',
a2Protocol: 'http',
a2Host: 'localhost',
a2Port: '3000',
a2Prefix: 'afront',
a2HomePage: 'http://localhost:3000/',
a2ApiPath: 'http://localhost:3000/api/',
a2ApiPath: 'api/',
a2ProxyPath: 'api/proxy/',
a2AdminUsername: 'root',
a2AdminPassword: 'root',
kibanaPrefix: 'kibana',
Expand Down Expand Up @@ -150,15 +153,13 @@ initFromEnv(exports.testValues, prefix, links);

// Some control instructions

exports.defaultValues.apiPath = 'http://' + exports.defaultValues.a2Host + ':' + exports.defaultValues.a2Port + '/api';
exports.testValues.apiPath = exports.defaultValues.apiPath;

exports.defaultValues.a2HomePage = 'http://' + exports.defaultValues.a2Host + ':' + exports.defaultValues.a2Port + '/';
exports.defaultValues.a2ApiPath = exports.defaultValues.a2HomePage + 'api/';
exports.testValues.a2ApiPath = exports.defaultValues.a2ApiPath;
exports.testValues.a2HomePage = exports.defaultValues.a2HomePage;
exports.defaultValues.a2HomePage = exports.defaultValues.a2Protocol + '://' + exports.defaultValues.a2Host + ':' + exports.defaultValues.a2Port + '/';

exports.testValues.a2AdminUsername = exports.defaultValues.a2AdminUsername;
exports.testValues.a2AdminPassword = exports.defaultValues.a2AdminPassword;

exports.defaultValues.basePath = process.env.BASE_PATH || exports.defaultValues.a2ProxyPath + exports.defaultValues.a2Prefix + '/';
exports.testValues.basePath = exports.defaultValues.basePath;

exports.defaultValues.apiPath = 'http://' + exports.defaultValues.a2Host + ':' + exports.defaultValues.a2Port + '/api';
exports.testValues.apiPath = exports.defaultValues.apiPath;
13 changes: 10 additions & 3 deletions app/viewRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ var express = require('express'),
router = express.Router();

var getBasePath = function(req) {

let proto = req.headers['x-forwarded-proto'];
let host = proto + '://' + req.headers['x-forwarded-host'];

if (req.protocol === 'https') {
return 'https://' + req.headers['x-forwarded-host'];
host = 'https://' + req.headers['x-forwarded-host'];
}

if (host.substr(-1) !== '/'){
host += '/';
}

var proto = req.headers['x-forwarded-proto'];
return proto + '://' + req.headers['x-forwarded-host'];
return host + req.app.config.basePath;
};

router.get('/loginbyplugin', function (req, res) {
Expand Down
2 changes: 1 addition & 1 deletion bin/signup-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var request = require('request');
var config = require(Path.resolve(__dirname, '../app/config.js'));
var appData = require(Path.resolve(__dirname, '../app/a-frontend-routes.js')).app;

var baseUsersAPI = config.a2.a2ApiPath;
var baseUsersAPI = config.a2.a2HomePage + config.a2.a2ApiPath;

request.post(baseUsersAPI + 'login', {
form: {
Expand Down

0 comments on commit 47183d6

Please sign in to comment.