2017-07-29 12:45:12 +00:00
|
|
|
import React from 'react'
|
|
|
|
|
|
|
|
export default class extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props)
|
|
|
|
this.state = { response: '' }
|
|
|
|
}
|
|
|
|
|
|
|
|
static async getInitialProps ({ pathname, query }) {
|
|
|
|
return {
|
|
|
|
pathname,
|
|
|
|
query,
|
|
|
|
queryString: Object.keys(query).join('')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount () {
|
|
|
|
const response = JSON.stringify(
|
|
|
|
await window
|
|
|
|
.fetch(`/api/${this.props.queryString}`)
|
|
|
|
.then(response => response.json().then(data => data)),
|
|
|
|
null,
|
|
|
|
2
|
|
|
|
)
|
|
|
|
this.setState({ response })
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<content>
|
|
|
|
<p>
|
2018-12-17 16:34:32 +00:00
|
|
|
/api/{this.props.queryString} routed to https://swapi.co/api/
|
|
|
|
{this.props.queryString}
|
2017-07-29 12:45:12 +00:00
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<a href='?people/2'>Try</a>
|
|
|
|
|
|
|
|
<a href='/'>Reset</a>
|
|
|
|
</p>
|
2018-12-17 16:34:32 +00:00
|
|
|
<pre>{this.state.response ? this.state.response : 'Loading...'}</pre>
|
2017-07-29 12:45:12 +00:00
|
|
|
</content>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|