Last active
December 16, 2018 14:20
-
-
Save talentlessguy/63f954d554648fbf3836e6c6a0f3f41a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const exp = require('express'); | |
const app = exp(); | |
app.listen(4000, () => console.log('Listening on 4000')); | |
app.use(exp.static('./')); | |
app.use((req, res, next) => { | |
res.header('Access-Control-Allow-Origin', '*') | |
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept') | |
res.json({ | |
"glossary": { | |
"title": "example glossary" | |
} | |
}); | |
next() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import './style.css'; | |
class NewsBlock extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
data: '' | |
} | |
} | |
componentDidMount() { | |
fetch('http://localhost:4000/',{ | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
}).catch(err => console.error(err) | |
).then(res => res.json()).then(json => this.setState({data: json})); | |
} | |
render() { | |
return <div> | |
{this.state.data} | |
</div> | |
} | |
} | |
ReactDOM.render( | |
<NewsBlock/>, | |
document.getElementById('root') | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "newsfeed", | |
"version": "0.1.0", | |
"private": true, | |
"proxy": "http://localhost:4000", | |
"dependencies": { | |
"npm-run-all": "^4.1.5", | |
"react": "^16.6.3", | |
"react-dom": "^16.6.3", | |
"react-scripts": "2.1.1" | |
}, | |
"scripts": { | |
"start": "react-scripts start", | |
"dev": "run-p server start", | |
"build": "react-scripts build", | |
"test": "react-scripts test", | |
"eject": "react-scripts eject", | |
"server": "node server_demo/server.js" | |
}, | |
"eslintConfig": { | |
"extends": "react-app" | |
}, | |
"browserslist": [ | |
">0.2%", | |
"not dead", | |
"not ie <= 11", | |
"not op_mini all" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment