Skip to content

Commit

Permalink
Merge pull request #107 from mbarto/http_proxy
Browse files Browse the repository at this point in the history
Fixes #106: integrated http-proxy as a submodule;
  • Loading branch information
mbarto committed Sep 10, 2015
2 parents b9de97a + c979b99 commit 3bc6977
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "geostore"]
path = geostore
url = https://github.com/geosolutions-it/geostore
[submodule "http-proxy"]
path = http-proxy
url = https://github.com/geosolutions-it/http-proxy.git
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
mvn clean install -Pgeostore,extjs,postgres,h2_disk
mvn clean install -Pgeostore,proxy,extjs,postgres,h2_disk
1 change: 1 addition & 0 deletions http-proxy
Submodule http-proxy added at 24c396
23 changes: 16 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,42 @@
<version>1.0-SNAPSHOT</version>
<name>MapStore 2</name>
<url>http://www.geo-solutions.it</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>


</dependencies>

<build>

</build>

<profiles>
<profile>
<id>geostore</id>

<modules>
<module>geostore/src</module>
</modules>


</profile>

<profile>
<id>proxy</id>

<modules>
<module>http-proxy</module>
</modules>

</profile>
</profiles>

<modules>
<module>web</module>
</modules>

</project>
2 changes: 1 addition & 1 deletion web/client/actions/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

var axios = require('axios');
var axios = require('../libs/ajax');

const MAP_CONFIG_LOADED = 'MAP_CONFIG_LOADED';
const MAP_CONFIG_LOAD_ERROR = 'MAP_CONFIG_LOAD_ERROR';
Expand Down
2 changes: 1 addition & 1 deletion web/client/actions/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

var axios = require('axios');
var axios = require('../libs/ajax');

const CHANGE_LOCALE = 'CHANGE_LOCALE';
const LOCALE_LOAD_ERROR = 'LOCALE_LOAD_ERROR';
Expand Down
2 changes: 1 addition & 1 deletion web/client/api/GeoStoreDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var axios = require('axios');
var axios = require('../libs/ajax');

/**
* API for local config
Expand Down
2 changes: 1 addition & 1 deletion web/client/api/MapConfigDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var axios = require('axios');
var axios = require('../libs/ajax');
var ConfigUtils = require('../utils/ConfigUtils');
/**
* API for local config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('This test for InfoButton', () => {

it('checks if the button contains only icon', () => {
const icon = 'info-sign';
const about = React.render(<InfoButton glyphicon={icon} hiddenText={true}/>, document.body);
const about = React.render(<InfoButton glyphicon={icon} hiddenText/>, document.body);
const aboutDom = React.findDOMNode(about);
const btn = aboutDom.getElementsByTagName('button').item(0);

Expand All @@ -133,7 +133,7 @@ describe('This test for InfoButton', () => {
});

it('checks if the button contains at least the default text', () => {
const about = React.render(<InfoButton hiddenText={true}/>, document.body);
const about = React.render(<InfoButton hiddenText/>, document.body);
const aboutDom = React.findDOMNode(about);
const btn = aboutDom.getElementsByTagName('button').item(0);

Expand All @@ -146,7 +146,7 @@ describe('This test for InfoButton', () => {

it('checks if the button contains at least the custom text', () => {
const customText = "testText";
const about = React.render(<InfoButton hiddenText={true} text={customText}/>, document.body);
const about = React.render(<InfoButton hiddenText text={customText}/>, document.body);
const aboutDom = React.findDOMNode(about);
const btn = aboutDom.getElementsByTagName('button').item(0);

Expand Down
2 changes: 1 addition & 1 deletion web/client/examples/home/containers/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var Viewer = React.createClass({
},
renderModules(locale) {
return (
<Grid fluid={true}>
<Grid fluid>
<Row className="show-grid">
<Col xs={12} md={6}>
<div>
Expand Down
34 changes: 34 additions & 0 deletions web/client/libs/__tests__/ajax-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright 2015, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

var expect = require('expect');
var axios = require('../ajax');

describe('Tests ajax library', () => {
it('uses proxy for requests not on the same origin', (done) => {
axios.get('http://fakeexternaldomain.mapstore2').then(() => {
done();
}).catch(ex => {
expect(ex.config).toExist();
expect(ex.config.url).toExist();
expect(ex.config.url).toContain('proxy/?url=');
done();
});
});

it('does not use proxy for requests on the same origin', (done) => {
axios.get('base/web/client/test-resources/testConfig.json').then((response) => {
expect(response.config).toExist();
expect(response.config.url).toExist();
expect(response.config.url).toBe('base/web/client/test-resources/testConfig.json');
done();
}).catch(ex => {
done(ex);
});
});
});
40 changes: 40 additions & 0 deletions web/client/libs/ajax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright 2015, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var axios = require('axios');

var proxy = '/mapstore/proxy/?url=';

axios.interceptors.request.use(config => {
var uri = config.url || '';
var sameOrigin = !(uri.indexOf("http") === 0);
var urlParts = !sameOrigin && uri.match(/([^:]*:)\/\/([^:]*:?[^@]*@)?([^:\/\?]*):?([^\/\?]*)/);
if (urlParts) {
let location = window.location;
sameOrigin =
urlParts[1] === location.protocol &&
urlParts[3] === location.hostname;
let uPort = urlParts[4];
let lPort = location.port;
if (uPort !== 80 && uPort !== "" || lPort !== "80" && lPort !== "") {
sameOrigin = sameOrigin && uPort === lPort;
}
}
if (!sameOrigin) {
let proxyUrl = config ? config.proxyUrl || proxy : proxy;
if (proxyUrl) {

if (proxyUrl.match(/^http:\/\//i) === null) {
proxyUrl = 'http://' + window.location.host + proxyUrl;
}
config.url = proxyUrl + encodeURIComponent(uri);
}
}
return config;
});

module.exports = axios;
7 changes: 7 additions & 0 deletions web/client/libs/leaflet.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
/**
* Copyright 2015, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = window.L;
7 changes: 7 additions & 0 deletions web/client/libs/openlayers.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
/**
* Copyright 2015, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = window.ol;
7 changes: 7 additions & 0 deletions web/client/libs/proj4.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
/**
* Copyright 2015, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = window.proj4;
12 changes: 11 additions & 1 deletion web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
<type>war</type>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>proxy</groupId>
<artifactId>http_proxy</artifactId>
<version>1.1-SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -203,6 +209,10 @@
<groupId>it.geosolutions.geostore</groupId>
<artifactId>geostore-webapp</artifactId>
</overlay>
<overlay>
<groupId>proxy</groupId>
<artifactId>http_proxy</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
Expand Down
18 changes: 17 additions & 1 deletion web/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<param-value>geostore.root</param-value>
</context-param>

<context-param>
<param-name>proxyPropPath</param-name>
<param-value>/proxy.properties</param-value>
</context-param>

<!-- <context-param> <param-name>log4jConfigLocation</param-name> <param-value>file:${config.dir}/log4j.xml</param-value>
</context-param> -->

Expand Down Expand Up @@ -49,10 +54,21 @@
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/rest/geostore/*</url-pattern>
</servlet-mapping>

<!-- Proxy Servlet -->
<servlet>
<servlet-name>HttpProxy</servlet-name>
<servlet-class>it.geosolutions.httpproxy.HTTPProxy</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HttpProxy</servlet-name>
<url-pattern>/proxy/*</url-pattern>
</servlet-mapping>

<!-- Default page to serve -->
<welcome-file-list>
Expand Down
3 changes: 3 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ module.exports = {
rewrite: rewriteUrl("/geostore/rest/$1"),
host: "mapstore.geo-solutions.it",
target: "http://mapstore.geo-solutions.it"
}, {
path: "/mapstore/proxy",
target: "http://localhost:8083"
}]
},

Expand Down

0 comments on commit 3bc6977

Please sign in to comment.