Skip to content

Instantly share code, notes, and snippets.

@hnry
Last active August 11, 2016 03:13
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 hnry/055e4e95e9f8314699dd6a12b37b0be3 to your computer and use it in GitHub Desktop.
Save hnry/055e4e95e9f8314699dd6a12b37b0be3 to your computer and use it in GitHub Desktop.
const {adapter, redirect, response} = require("spirit").node
const route = require("spirit-router")
const redirector = () => {
if (true) {
return redirect("/another_page")
}
// both returns are equal below, can use some helper functions for creating
// a response, just like redirect() will create a redirect response
return response("Condition failed, didn't redirect")
// return "Condition failed, didn't redirect"
}
const app = route.define([
route.get("/", [], redirector),
route.get("/another_page", "Hi from another page")
])
const http = require("http")
http.createServer(adapter(app)).listen(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment