Skip to content

Instantly share code, notes, and snippets.

@xudaolong
Last active November 1, 2018 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xudaolong/6b3c36c38a617ff2854460ac83efab32 to your computer and use it in GitHub Desktop.
Save xudaolong/6b3c36c38a617ff2854460ac83efab32 to your computer and use it in GitHub Desktop.
react-router|-|&tag=react
import React, { Component, PropTypes } from 'react';
import Loading from 'components/Loading';
export default class List extends Component {
static propTypes = {
data: PropTypes.array.isRequired,
fetch: PropTypes.func.isRequired,
isFetching: PropTypes.bool.isRequired,
};
componentDidMount() {
this.props.fetch();
}
render() {
const { isFetching, data } = this.props;
return (
<ul>
{isFetching && <Loading message="Retrieving posts..." />}
{data.map(entry => <li key={entry.id}>{entry.title}</li>)}
</ul>
)
}
}
server {
...
location / {
try_files $uri /index.html;
}
}
const express = require('express')
const path = require('path')
const port = process.env.PORT || 8080
const app = express()
// serve static assets normally
app.use(express.static(__dirname + '/public'))
// handle every other route with index.html, which will contain
// a script tag to your application's JavaScript file(s).
app.get('*', function (request, response){
response.sendFile(path.resolve(__dirname, 'public', 'index.html'))
})
app.listen(port)
console.log("server started on port " + port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment