Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pretty proxy error page

commit a0b09f2d2007caa8c45bc533dc38b88028167ec7 1 parent 39d8a1b
@josh josh authored
View
1  Cakefile
@@ -27,6 +27,7 @@ buildTemplates = (callback) ->
compile("http_server/application_not_found.html")
compile("http_server/error_starting_application.html")
compile("http_server/layout.html")
+ compile("http_server/proxy_error.html")
compile("http_server/rackup_file_missing.html")
compile("http_server/welcome.html")
compile("installer/cx.pow.firewall.plist")
View
23 lib/http_server.js
@@ -169,17 +169,22 @@
}, this));
};
HttpServer.prototype.handleProxyRequest = function(req, res, next) {
- var port, urlObj, _ref2;
- if (!(port = req.pow.url)) {
+ var hostname, port, proxy, _ref2;
+ if (!req.pow.url) {
return next();
}
- urlObj = url.parse(req.pow.url);
- if ((_ref2 = this.proxy) == null) {
- this.proxy = new HttpProxy();
- }
- this.proxy.proxyRequest(req, res, {
- host: urlObj.hostname,
- port: urlObj.port
+ _ref2 = url.parse(req.pow.url), hostname = _ref2.hostname, port = _ref2.port;
+ proxy = new HttpProxy();
+ proxy.on('proxyError', function(err, req, res) {
+ return renderResponse(res, 500, "proxy_error", {
+ err: err,
+ hostname: hostname,
+ port: port
+ });
+ });
+ proxy.proxyRequest(req, res, {
+ host: hostname,
+ port: port
});
return req.pow.resume();
};
View
54 lib/templates/http_server/proxy_error.html.js
@@ -0,0 +1,54 @@
+module.exports = function(__obj) {
+ var _safe = function(value) {
+ if (typeof value === 'undefined' && value == null)
+ value = '';
+ var result = new String(value);
+ result.ecoSafe = true;
+ return result;
+ };
+ return (function() {
+ var __out = [], __self = this, _print = function(value) {
+ if (typeof value !== 'undefined' && value != null)
+ __out.push(value.ecoSafe ? value : __self.escape(value));
+ }, _capture = function(callback) {
+ var out = __out, result;
+ __out = [];
+ callback.call(this);
+ result = __out.join('');
+ __out = out;
+ return _safe(result);
+ };
+ (function() {
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+ _print(_safe(this.renderTemplate("layout", {
+ title: "Proxy Error"
+ }, __bind(function() {
+ return _capture(__bind(function() {
+ _print(_safe('\n <h1 class="err">Proxy Error</h1>\n <h2>Couldn\'t proxy request to <code>'));
+ _print(this.hostname);
+ _print(_safe(':'));
+ _print(this.port);
+ _print(_safe('</code>.</h2>\n <section>\n <pre class="breakout small_text"><strong>'));
+ _print(this.err);
+ return _print(_safe('</strong>\n </section>\n'));
+ }, this));
+ }, this))));
+ _print(_safe('\n'));
+ }).call(this);
+
+ return __out.join('');
+ }).call((function() {
+ var obj = {
+ escape: function(value) {
+ return ('' + value)
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;');
+ },
+ safe: _safe
+ }, key;
+ for (key in __obj) obj[key] = __obj[key];
+ return obj;
+ })());
+};
View
14 src/http_server.coffee
@@ -176,13 +176,15 @@ module.exports = class HttpServer extends connect.HTTPServer
# If the request object is annotated with a url, proxy the
# request off to the hostname and port.
handleProxyRequest: (req, res, next) =>
- return next() unless port = req.pow.url
- urlObj = url.parse req.pow.url
+ return next() unless req.pow.url
+ {hostname, port} = url.parse req.pow.url
- @proxy ?= new HttpProxy()
- @proxy.proxyRequest req, res,
- host: urlObj.hostname
- port: urlObj.port
+ proxy = new HttpProxy()
+ proxy.on 'proxyError', (err, req, res) ->
+ renderResponse res, 500, "proxy_error",
+ {err, hostname, port}
+
+ proxy.proxyRequest req, res, {host: hostname, port}
req.pow.resume()
View
7 src/templates/http_server/proxy_error.html.eco
@@ -0,0 +1,7 @@
+<%- @renderTemplate "layout", title: "Proxy Error", => %>
+ <h1 class="err">Proxy Error</h1>
+ <h2>Couldn't proxy request to <code><%= @hostname %>:<%= @port %></code>.</h2>
+ <section>
+ <pre class="breakout small_text"><strong><%= @err %></strong>
+ </section>
+<% end %>

0 comments on commit a0b09f2

Please sign in to comment.
Something went wrong with that request. Please try again.