www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 33625f7b08708dd5d35eceb6664703465ee3ea9d
parent 3caccbf933e392778c5d82b47599d8004f7b04f8
Author: Ben Alpert <spicyjalapeno@gmail.com>
Date:   Sun,  7 Jul 2013 14:13:25 -0700

Catch server errors and return 500

Reviewers: xymostech

Reviewed By: xymostech

Differential Revision: http://phabricator.benalpert.com/D39

Diffstat:
MMakefile | 4++--
Mserver.js | 12++++++++++--
2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ FILES=parser.js style.css build.js index.html -.PHONY: build ship copy server +.PHONY: build ship copy serve build: parser.js ship: build @@ -14,5 +14,5 @@ copy: build parser.js: parser.jison ./node_modules/.bin/jison parser.jison -server: +serve: node server.js diff --git a/server.js b/server.js @@ -9,21 +9,29 @@ var app = express(); app.use(express.logger()); -app.get("/MJLite.js", function(req, res) { +app.get("/MJLite.js", function(req, res, next) { var b = browserify(); b.add("./MJLite"); b.transform(jisonify); var stream = b.bundle({standalone: "MJLite"}); + var body = ""; stream.on("data", function(s) { body += s; }); + stream.on("error", function(e) { next(e); }); stream.on("end", function() { res.setHeader("Content-Type", "text/javascript"); res.send(body); }); }); -app.use(express.static(path.join(__dirname, 'static'))); +app.use(express.static(path.join(__dirname, "static"))); + +app.use(function(err, req, res, next) { + console.error(err.stack); + res.setHeader("Content-Type", "text/plain"); + res.send(500, err.stack); +}); app.listen(7936); console.log("Serving on http://0.0.0.0:7936/ ...");