Skip to content

Commit

Permalink
Add basic logic for fetching data from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
imWildCat committed Apr 30, 2018
1 parent 66bdf0b commit 81c4160
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
30 changes: 26 additions & 4 deletions frontend/src/components/ProxyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import * as React from "react";
import axios from 'axios';

export interface AppState {
timesClicked: number;
on: boolean;
proxies: Array<any>,
}

export default class ProxyIPList extends React.Component<{}, AppState> {
private initialState: AppState = {timesClicked: 0, on: false};
private initialState: AppState = {proxies: []};

constructor(props: {}) {
super(props);
Expand All @@ -19,12 +18,35 @@ export default class ProxyIPList extends React.Component<{}, AppState> {
return (
<div>
proxy ip list

{this.renderList()}
</div>
);
}

renderList(): JSX.Element {
return (
<div>
{this.state.proxies.map(p => {
return (
<div key={'proxy-' + p.id}>
<p>{p.ip}</p>
</div>
)
})}
</div>
);
}

componentDidMount() {
axios.get('http://localhost:8000/api/v1/proxies')
this.loadData();
}

async loadData() {
const response = await axios.get('http://localhost:8000/api/v1/proxies');
const proxies: [any] = response.data.proxies;
console.log(proxies);
this.setState({proxies: proxies})
}

}
1 change: 0 additions & 1 deletion frontend/src/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
body {
background-color: #0e84b5;
}
4 changes: 3 additions & 1 deletion scylla/web/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

CORS(app)


# @app.route('/')
# async def test(request: Request):
# return json({'hello': 'world', 'args': request.raw_args})


@app.route('/api/v1/proxies')
async def api_v1_proxies(request: Request):
proxies = ProxyIP.select().where(ProxyIP.latency > 0).where(ProxyIP.is_valid == True) \
proxies = ProxyIP.select().where(ProxyIP.latency > 0).where(ProxyIP.latency < 9999) \
.where(ProxyIP.is_valid == True) \
.order_by(ProxyIP.updated_at.desc(), ProxyIP.latency).limit(20)

logger.debug('Perform SQL query: ', proxies.sql())
Expand Down

0 comments on commit 81c4160

Please sign in to comment.