Update API

This commit is contained in:
LordMathis 2017-10-31 18:46:29 +01:00
parent 9884782386
commit 95dcc7f347
3 changed files with 26 additions and 12 deletions

View File

@ -1,11 +1,24 @@
import React from 'react';
import React, {Component} from 'react';
export const Blog = (props) => (
export default class Blog extends Component {
render() {
if (this.props.data.isLoading) {
return (
<h1>Loading</h1>
);
}
return (
<div>
<div className="content">
<h1>{ props.data.isLoading ? 'Loading...' : 'Blog' }</h1>
<h1>Blog</h1>
<div>{this.props.data.posts[0].published}</div>
<div>{this.props.data.posts[0].filename}</div>
</div>
</div>
);
export default Blog;
}
};

View File

@ -16,6 +16,7 @@ export default class BlogContainer extends Component {
axios.get('/api/blog').then((res) => {
this.setState({
isLoading: false,
posts: res.data,
});
})
}

View File

@ -1,7 +1,7 @@
const data = require('./data.json');
module.exports = function(app) {
app.get('/api/blog', ((req, res) => {
res.json({
"blog": "Blog hello"
});
res.json(data.posts);
}));
}