Skip to content

Instantly share code, notes, and snippets.

@rook2pawn
Last active April 18, 2018 10:31
Show Gist options
  • Save rook2pawn/66d6fa00a43de42ce3dc489b4980370b to your computer and use it in GitHub Desktop.
Save rook2pawn/66d6fa00a43de42ce3dc489b4980370b to your computer and use it in GitHub Desktop.
// app.js
var html = require('choo/html')
var choo = require('choo')
var app = choo() // 1.
app.route('/', view) // 2.
app.route('/second', second) // 2.
app.mount('body') // 3.
function view () { // 4.
return html`
<body>
<h2>Hello World</h2>
<a href="/second">
Navigate to the next route.
</a>
</body>
`
}
function second () {
return html`
<body>
<a href="/">
Navigate back.
</a>
</body>
`
}
// server.js
const http = require("http")
const ecstatic = require("ecstatic")(__dirname)
const server = http.createServer(ecstatic)
server.listen(5150)
@rook2pawn
Copy link
Author

rook2pawn commented Apr 18, 2018

// server-that-fixes.js

const http = require("http")
const ecstatic = require("ecstatic")(__dirname)
const server = http.createServer((req,res) => {

  if (req.url == "/second") {
    req.url = "/"
    return ecstatic(req,res)
  }
  return ecstatic(req,res)
})

server.listen(5150)

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