From f339d90d00e935afa32acf581155d8f43bf83508 Mon Sep 17 00:00:00 2001 From: Niklas Date: Fri, 12 Feb 2021 16:27:34 +0100 Subject: [PATCH] proxy pass nextcloud request --- build-docker.sh | 2 +- docker-compose.yml | 2 +- nginx.conf | 5 ++--- package.json | 1 + src/App.tsx | 18 +++--------------- 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/build-docker.sh b/build-docker.sh index 288044b..bb35b17 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -1,3 +1,3 @@ #!/usr/bin/env sh -sudo docker build -t docker.kapelle.org/ncpb . +sudo docker build -t docker.kapelle.org/ncpb:latest . diff --git a/docker-compose.yml b/docker-compose.yml index 691ae38..e7cc6e5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,4 +5,4 @@ services: ports: - "8080:80" environment: - - ENDPOINT=https://your.nextcloud.org/ + - ENDPOINT=http://nextclouddockerip diff --git a/nginx.conf b/nginx.conf index 0a8c6c4..ce2f1dc 100644 --- a/nginx.conf +++ b/nginx.conf @@ -11,9 +11,8 @@ http { try_files ${DOLLAR}uri /index.html; } - location = /api/endpoint { - - return 200 '${ENDPOINT}'; + location ^~ /index.php/s/ { + proxy_pass '${ENDPOINT}'; } } diff --git a/package.json b/package.json index 9235aca..6e4a4d9 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "react-syntax-highlighter": "^15.4.3", "typescript": "^4.1.2" }, + "proxy":"https://your.nextcloud.org", "scripts": { "start": "react-scripts start", "build": "react-scripts build", diff --git a/src/App.tsx b/src/App.tsx index 1954dce..bfff4e6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -29,22 +29,10 @@ function App(props: Props) { const [content,setContent] = useState(""); const [title,setTitle] = useState(""); const [lang,setLang] = useState("text"); - const [endpoint,setEndpoint] = useState(""); - - useEffect(()=>{ - (async () =>{ - setEndpoint(await (await fetch("/api/endpoint")).text()); - })() - },[]) useEffect(()=>{ (async ()=>{ - if (!endpoint){ - // Still loading endpoint - return - } - - const response = await fetch(`${endpoint}/index.php/s/${props.shareID}/download`); + const response = await fetch(`/index.php/s/${props.shareID}/download`); if (response.status === 404){ // File not found @@ -67,10 +55,10 @@ function App(props: Props) { // TODO display error } })() - },[props.shareID,endpoint]) + },[props.shareID]) function downloadClick() { - window.open(`${endpoint}/index.php/s/${props.shareID}/download`, "_self"); + window.open(`/index.php/s/${props.shareID}/download`, "_self"); } return (