Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choropleth: allow to use custom maps #4599

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
6 changes: 5 additions & 1 deletion client/app/visualizations/choropleth/hooks/useLoadGeoJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import createReferenceCountingCache from "@/lib/referenceCountingCache";

const cache = createReferenceCountingCache();

function withProxy(url) {
return `/resource-proxy?url=${encodeURIComponent(url)}`;
}

export default function useLoadGeoJson(url) {
const [geoJson, setGeoJson] = useState(null);
const [isLoading, setIsLoading] = useState(false);
Expand All @@ -14,7 +18,7 @@ export default function useLoadGeoJson(url) {
setIsLoading(true);
let cancelled = false;

const promise = cache.get(url, () => axios.get(url).catch(() => null));
const promise = cache.get(url, () => axios.get(withProxy(url)).catch(() => null));
promise.then(data => {
if (!cancelled) {
setGeoJson(isObject(data) ? data : null);
Expand Down
11 changes: 10 additions & 1 deletion redash/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import jsonify
from flask import jsonify, request, Response
from flask_login import login_required
import requests

from redash.handlers.api import api
from redash.handlers.base import routes
Expand All @@ -22,6 +23,14 @@ def status_api():
return jsonify(status)


@routes.route("/resource-proxy", methods=["GET"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put this in the api namespace (i.e. /api/resource-proxy) to avoid issues in environments like our deployment preview.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done c7b1345

def resource_proxy():
response = requests.get(request.args.get('url'))
allow_headers = ['content-type']
headers = [(name, value) for (name, value) in response.raw.headers.items() if name.lower() in allow_headers]
return Response(response.content, response.status_code, headers)


def init_app(app):
from redash.handlers import (
embed,
Expand Down