Skip to content

Instantly share code, notes, and snippets.

@DylanPiercey
Last active June 12, 2016 18:34
Show Gist options
  • Save DylanPiercey/3a07786eed83950b13b8 to your computer and use it in GitHub Desktop.
Save DylanPiercey/3a07786eed83950b13b8 to your computer and use it in GitHub Desktop.
An isomorphic Rill snippet.
// Use an isomorphic form-data/body parser.
app.use(require("@rill/body")());
// Register our form page route as normal.
app.get("/my-form-page", ({ req, res })=> {
res.body = <MyForm/>
});
// Setup our post route.
app.post("/my-form-submit", ({ req, res })=> {
// Analyze the response body (works in node and the browser)
req.body; //-> { email: ... }
req.files; // Any files submitted with the form.
// Perform the business logic (typically calling some api)
...
// Finally take the user somewhere meaningful.
res.redirect("/thank-you");
});
function MyForm (props) {
return (
<html>
<head>
<title>My App - Form</title>
</head>
<body>
Please, your data is important for my business!
<form action="/my-form-submit" method="POST">
Email: <input name="email">
<button type="submit">Subscribe</button>
</form>
<a href="/">Take me back!</a>
<script src="/app.js"/>
</body>
</html>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment