I just got in touch with the link today and wanted to solve the simillar problem by serving a simple HTML file. In my case, I wanted to show 404 when previous intermediaries did not complete the request.
I create a show404 function and then you can do something like app.use(show404) . Here, my CoffeScript for this basically inspired the errorHandler source code for the error.
show404 = (req, res, next) -> res.statusCode = 404 res.setHeader 'Content-Type', 'text/html; charset=utf-8' html_path = require("path").resolve('.tmp/404.html') require('fs').readFile html_path, (err, data)-> throw err if err console.log "DATA:", data res.end data
David Pelaez
source share