-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: remove ui element for force proxy and Allow not secure layers * fix: ajax logic changed, autoDetectCORS is set to true by default * new central CORS util file created and used in ajax * checking CORS before adding in common layer file * null check on getProxyUrl * updated individual layer considring to use proxy if needed * avoid proxy cache to update if response is not okey * enable user to add http url, show warning instead of error, warning text updated * test cases updated * fix: resolve conflicts with url check * fixed the failed test * review cesium layers * include add method in model layer * improve http check for openlayers wms layer * fix tests --------- Co-authored-by: allyoucanmap <stefano.bovio@geosolutionsgroup.com>
- Loading branch information
1 parent
c4af813
commit 8b2d33e
Showing
39 changed files
with
644 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2024, 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. | ||
*/ | ||
|
||
import url from 'url'; | ||
import { needProxy } from '../utils/ProxyUtils'; | ||
|
||
let proxyCache = {}; | ||
|
||
|
||
const getBaseUrl = (uri) => { | ||
const urlParts = url.parse(uri); | ||
return urlParts.protocol + "//" + urlParts.host + urlParts.pathname; | ||
}; | ||
/** | ||
* Set the proxy value for cached uri | ||
* @param {string} uri - uri string to test | ||
* @param {boolean} value - value to cache | ||
* @returns the passed value | ||
*/ | ||
export const setProxyCacheByUrl = (uri, value)=>{ | ||
const baseUrl = getBaseUrl(uri); | ||
proxyCache[baseUrl] = value; | ||
return value; | ||
}; | ||
/** | ||
* Get the proxy value for cached uri | ||
* @param {string} uri - uri string to test | ||
* @returns true, false or undefined, if undefined means the value has not been stored | ||
*/ | ||
export const getProxyCacheByUrl = (uri)=>{ | ||
const baseUrl = getBaseUrl(uri); | ||
return proxyCache[baseUrl]; | ||
}; | ||
/** | ||
* Perform a fetch request to test if a service support CORS | ||
* @param {string} uri - uri string to test | ||
* @returns true if the proxy is required | ||
*/ | ||
export const testCors = (uri) => { | ||
const proxy = getProxyCacheByUrl(uri); | ||
if (needProxy(uri) === false) { | ||
setProxyCacheByUrl(uri, false); | ||
return Promise.resolve(false); | ||
} | ||
if (proxy !== undefined) { | ||
return Promise.resolve(proxy); | ||
} | ||
return fetch(uri, { | ||
method: 'GET', | ||
mode: 'cors' | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
return false; | ||
} | ||
return setProxyCacheByUrl(uri, false); | ||
}) | ||
.catch(() => { | ||
// in server side error it goes to response(then) anyway, so we can assume that if we get here we have a cors error with no previewable response | ||
return setProxyCacheByUrl(uri, true); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.