From 974e2c9011f7ec2acf2309116f3de2c07bf19cf8 Mon Sep 17 00:00:00 2001 From: xmcp Date: Tue, 21 Aug 2018 13:53:58 +0800 Subject: [PATCH] api proxy test --- public/_redirects | 1 + src/Flows.js | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 public/_redirects diff --git a/public/_redirects b/public/_redirects new file mode 100644 index 0000000..04ec040 --- /dev/null +++ b/public/_redirects @@ -0,0 +1 @@ +/api_proxy/* http://www.pkuhelper.com:10301/services/pkuhole/:splat 200 \ No newline at end of file diff --git a/src/Flows.js b/src/Flows.js index ae4c2f5..95cbffb 100644 --- a/src/Flows.js +++ b/src/Flows.js @@ -6,6 +6,7 @@ import LazyLoad from 'react-lazyload'; const IMAGE_BASE='http://www.pkuhelper.com/services/pkuhole/images/'; const AUDIO_BASE='http://www.pkuhelper.com/services/pkuhole/audios/'; +const API_BASE=window.location.protocol==='https:' ? '/api_proxy' : 'http://www.pkuhelper.com:10301/services/pkuhole'; const SEARCH_PAGESIZE=50; function Reply(props) { @@ -68,7 +69,7 @@ class FlowItemRow extends Component { load_replies() { console.log('fetching reply',this.info.pid); - fetch('http://www.pkuhelper.com:10301/services/pkuhole/api.php?action=getcomment&pid='+this.info.pid) + fetch(API_BASE+'/api.php?action=getcomment&pid='+this.info.pid) .then((res)=>res.json()) .then((json)=>{ if(json.code!==0) @@ -139,7 +140,7 @@ export class Flow extends Component { if(page===this.state.loaded_pages+1) { console.log('fetching page',page); if(this.state.mode==='list') { - fetch('http://www.pkuhelper.com:10301/services/pkuhole/api.php?action=getlist&p='+page) + fetch(API_BASE+'/api.php?action=getlist&p='+page) .then((res)=>res.json()) .then((json)=>{ if(json.code!==0) @@ -158,7 +159,7 @@ export class Flow extends Component { }); } else if(this.state.mode==='search') { fetch( - 'http://www.pkuhelper.com:10301/services/pkuhole/api.php?action=search'+ + API_BASE+'/api.php?action=search'+ '&pagesize='+SEARCH_PAGESIZE*page+ '&keywords='+encodeURIComponent(this.state.search_param) ) @@ -183,7 +184,7 @@ export class Flow extends Component { } else if(this.state.mode==='single') { const pid=parseInt(this.state.search_param.substr(1),10); fetch( - 'http://www.pkuhelper.com:10301/services/pkuhole/api.php?action=getone'+ + API_BASE+'/api.php?action=getone'+ '&pid='+pid ) .then((res)=>res.json())