Skip to content

Instantly share code, notes, and snippets.

@DylanPiercey
Last active August 2, 2016 14:40
Show Gist options
  • Save DylanPiercey/4eab06ee4b5facbf7ee2 to your computer and use it in GitHub Desktop.
Save DylanPiercey/4eab06ee4b5facbf7ee2 to your computer and use it in GitHub Desktop.
An Isomorphic Rill snippet.
// Creating an app is familiar.
const app = require("rill")();
// Lets pull in some middleware!
app.use(require("@rill/logger")()); // Setup logging.
app.use(require("@rill/react")()); // Setup our react renderer.
// Lets make our index page!
app.get("/", ({ req, res })=> {
// Simply set the response body to a React Element.
// This will send html in the server and
// update the dom in the browser.
res.body = <MyApp title="Rill"/>;
});
// Listen will start a node server, or start the event listeners in the browser.
app.listen({ port: 3000, ip: "0.0.0.0" });
// Extremely simple full page React Component.
function MyApp (props) {
// Using JSX
return (
<html>
<head>
<title>My App - Home</title>
</head>
<body>
Welcome to { props.title } life.
<a href="/away">Take me away!</a>
<script src="/app.js"/>
</body>
</html>
);
}
@bahmutov
Copy link

bahmutov commented Aug 2, 2016

Hi!
Is this code in some repo? I just want to run this locally to play with this, and was wondering about bundling tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment