Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add a window.onerror handler to show client side errors in the consol…

…e while debugging
  • Loading branch information...
commit 33b22c64d13f3c83b4698a8d91dbc1f28fbd421b 1 parent 06aecdd
Konstantin Käfer kkaefer authored
9 assets/debug.js
... ... @@ -0,0 +1,9 @@
  1 +window.onerror = function(message, url, line) {
  2 + $.ajax('/api/Error', {
  3 + data: {
  4 + message: message,
  5 + url: url,
  6 + line: line
  7 + }
  8 + });
  9 +};
15 servers/Core.bones
... ... @@ -1,3 +1,4 @@
  1 +var env = process.env.NODE_ENV || 'development';
1 2 var middleware = require('..').middleware;
2 3
3 4 server = Bones.Server.extend({});
@@ -6,7 +7,21 @@ server.prototype.port = 3000;
6 7
7 8 server.prototype.initialize = function(app) {
8 9 this.port = app.config.port || this.port;
  10 +
  11 + // Middleware provides body decoding, CSRF validation et al.
  12 + // Place other servers before this one ONLY when you intend to circumvent
  13 + // these safeguards.
9 14 this.use(new servers['Middleware'](app));
  15 +
  16 + // Debugging server provides facilities for easier client side debugging.
  17 + if (env === 'development') {
  18 + this.use(new servers['Debug'](app));
  19 + }
  20 +
  21 + // The Route server provides default routes for /api/Model as well as
  22 + // the /assets/bones routes.
10 23 this.use(new servers['Route'](app));
  24 +
  25 + // The Asset server provides each plugin's asset folder at /asset/pluginname.
11 26 this.use(new servers['Asset'](app));
12 27 };
16 servers/Debug.bones
... ... @@ -0,0 +1,16 @@
  1 +var env = process.env.NODE_ENV || 'development';
  2 +
  3 +server = Bones.Server.extend({
  4 + initialize: function(app) {
  5 + _.bindAll(this, 'logError');
  6 + if (env === 'development') {
  7 + this.get('/api/Error', this.logError);
  8 + }
  9 + },
  10 +
  11 + logError: function(req, res, next) {
  12 + console.error("Client Error: %s\n at %s:%d",
  13 + req.query.message, req.query.url, req.query.line);
  14 + res.send();
  15 + }
  16 +});
5 servers/Route.bones
... ... @@ -1,3 +1,4 @@
  1 +var env = process.env.NODE_ENV || 'development';
1 2 var headers = { 'Content-Type': 'application/json' };
2 3
3 4 server = Bones.Server.extend({});
@@ -27,6 +28,10 @@ server.prototype.assets = {
27 28 templates: new mirror([], options)
28 29 };
29 30
  31 +if (env === 'development') {
  32 + server.prototype.assets.core.unshift(require.resolve('bones/assets/debug'));
  33 +}
  34 +
30 35 // TODO: This should be moved to the initialize method!
31 36 server.prototype.assets.all = new mirror([
32 37 server.prototype.assets.vendor,

0 comments on commit 33b22c6

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