proxy pass nextcloud request

This commit is contained in:
Niklas 2021-02-12 16:27:34 +01:00
parent d2db386693
commit f339d90d00
5 changed files with 8 additions and 20 deletions

View File

@ -1,3 +1,3 @@
#!/usr/bin/env sh #!/usr/bin/env sh
sudo docker build -t docker.kapelle.org/ncpb . sudo docker build -t docker.kapelle.org/ncpb:latest .

View File

@ -5,4 +5,4 @@ services:
ports: ports:
- "8080:80" - "8080:80"
environment: environment:
- ENDPOINT=https://your.nextcloud.org/ - ENDPOINT=http://nextclouddockerip

View File

@ -11,9 +11,8 @@ http {
try_files ${DOLLAR}uri /index.html; try_files ${DOLLAR}uri /index.html;
} }
location = /api/endpoint { location ^~ /index.php/s/ {
proxy_pass '${ENDPOINT}';
return 200 '${ENDPOINT}';
} }
} }

View File

@ -15,6 +15,7 @@
"react-syntax-highlighter": "^15.4.3", "react-syntax-highlighter": "^15.4.3",
"typescript": "^4.1.2" "typescript": "^4.1.2"
}, },
"proxy":"https://your.nextcloud.org",
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",

View File

@ -29,22 +29,10 @@ function App(props: Props) {
const [content,setContent] = useState<string>(""); const [content,setContent] = useState<string>("");
const [title,setTitle] = useState<string>(""); const [title,setTitle] = useState<string>("");
const [lang,setLang] = useState<string>("text"); const [lang,setLang] = useState<string>("text");
const [endpoint,setEndpoint] = useState<string>("");
useEffect(()=>{
(async () =>{
setEndpoint(await (await fetch("/api/endpoint")).text());
})()
},[])
useEffect(()=>{ useEffect(()=>{
(async ()=>{ (async ()=>{
if (!endpoint){ const response = await fetch(`/index.php/s/${props.shareID}/download`);
// Still loading endpoint
return
}
const response = await fetch(`${endpoint}/index.php/s/${props.shareID}/download`);
if (response.status === 404){ if (response.status === 404){
// File not found // File not found
@ -67,10 +55,10 @@ function App(props: Props) {
// TODO display error // TODO display error
} }
})() })()
},[props.shareID,endpoint]) },[props.shareID])
function downloadClick() { function downloadClick() {
window.open(`${endpoint}/index.php/s/${props.shareID}/download`, "_self"); window.open(`/index.php/s/${props.shareID}/download`, "_self");
} }
return ( return (