Skip to content
This repository
Browse code

Catch errors when loading code on demand, plus minor tweaks

  • Loading branch information...
commit c7841066c9844a024f0b10eb911c82d1e5607927 1 parent 3cea26c
Owen Barnes owenb authored
2  doc/guide/en/client_side_code.md
Source Rendered
@@ -19,7 +19,7 @@ While we try to keep the experience between browser and server as similar as pos
19 19
20 20 #### 'libs' - Legacy (non Common JS) Libraries
21 21
22   -Any file which lives in any directory called 'libs' will NOT be served as a module. Instead these files will be sent as-is without any modification. Typically you'll want to ensure jQuery and other libraries which use the `window` variable are always placed in a `/client/code` directory called 'libs'.
  22 +Any file which lives in a directory called 'libs' will NOT be served as a module. Instead these files will be sent as-is without any modification. Typically you'll want to ensure jQuery and other libraries which use the `window` variable are always placed in a `/client/code` directory called 'libs'.
23 23
24 24 As load order is critically important for non Common JS libraries **either** name your files alphanumerically within the `libs` directory **or** list each file explicitly in your `ss.client.define()` command - your choice.
25 25
2  lib/cli/generate.js
@@ -86,7 +86,7 @@ exports.generate = function(program) {
86 86 clientFiles.css.push('libs/reset.css');
87 87 clientFiles.css.push('app.styl');
88 88 }
89   - appjs = "// My SocketStream 0.3 app\n\nvar http = require('http'),\n ss = require('socketstream');\n\n// Define a single-page client\nss.client.define('main', {\n view: 'app." + viewExtension + "',\n css: ['" + (clientFiles.css.join("', '")) + "'],\n code: ['" + (clientFiles.code.join("', '")) + "'],\n tmpl: '*'\n});\n\n// Serve this client on the root URL\nss.http.route('/', function(req, res){\n res.serveClient('main');\n});\n";
  89 + appjs = "// My SocketStream 0.3 app\n\nvar http = require('http'),\n ss = require('socketstream');\n\n// Define a single-page client called 'main'\nss.client.define('main', {\n view: 'app." + viewExtension + "',\n css: ['" + (clientFiles.css.join("', '")) + "'],\n code: ['" + (clientFiles.code.join("', '")) + "'],\n tmpl: '*'\n});\n\n// Serve this client on the root URL\nss.http.route('/', function(req, res){\n res.serveClient('main');\n});\n";
90 90 if (selectedFormatters.length > 0) {
91 91 appjs += "\n// Code Formatters\n";
92 92 }
26 lib/client/serve/ondemand.js
... ... @@ -1,6 +1,8 @@
1 1 // Generated by CoffeeScript 1.3.3
2 2 var magicPath, pathlib, queryCache, utils;
3 3
  4 +require('colors');
  5 +
4 6 pathlib = require('path');
5 7
6 8 magicPath = require('../magic_path');
@@ -32,15 +34,21 @@ module.exports = function(ss, router, options) {
32 34 dir = pathlib.join(ss.root, options.dirs.code);
33 35 files = magicPath.files(dir, [path]);
34 36 return files.forEach(function(file) {
35   - return asset.js(file, {
36   - pathPrefix: path,
37   - compress: options.packAssets
38   - }, function(js) {
39   - output.push(js);
40   - if (output.length === files.length) {
41   - return cb(output.join("\n"));
42   - }
43   - });
  37 + var description;
  38 + try {
  39 + return asset.js(file, {
  40 + pathPrefix: path,
  41 + compress: options.packAssets
  42 + }, function(js) {
  43 + output.push(js);
  44 + if (output.length === files.length) {
  45 + return cb(output.join("\n"));
  46 + }
  47 + });
  48 + } catch (e) {
  49 + description = e.stack && e.stack.split("\n")[0] || 'Unknown Error';
  50 + return ss.log(("! Unable to load " + file + " on demand:").red, description);
  51 + }
44 52 });
45 53 };
46 54 worker = function(request, response, path, cb) {
2  src/cli/generate.coffee
@@ -94,7 +94,7 @@ exports.generate = (program) ->
94 94 var http = require('http'),
95 95 ss = require('socketstream');
96 96
97   -// Define a single-page client
  97 +// Define a single-page client called 'main'
98 98 ss.client.define('main', {
99 99 view: 'app.#{viewExtension}',
100 100 css: ['#{clientFiles.css.join("', '")}'],
14 src/client/serve/ondemand.coffee
@@ -2,6 +2,7 @@
2 2 # ----------------------
3 3 # Serves assets to browsers on demand, caching responses in production mode
4 4
  5 +require('colors')
5 6 pathlib = require('path')
6 7 magicPath = require('../magic_path')
7 8 utils = require('./utils')
@@ -30,10 +31,15 @@ module.exports = (ss, router, options) ->
30 31 dir = pathlib.join(ss.root, options.dirs.code)
31 32 files = magicPath.files(dir, [path])
32 33 files.forEach (file) ->
33   - asset.js file, {pathPrefix: path, compress: options.packAssets}, (js) ->
34   - output.push(js)
35   - if output.length == files.length # last file
36   - cb(output.join("\n"))
  34 + try
  35 + asset.js file, {pathPrefix: path, compress: options.packAssets}, (js) ->
  36 + output.push(js)
  37 + if output.length == files.length # last file
  38 + cb(output.join("\n"))
  39 + catch e
  40 + description = e.stack && e.stack.split("\n")[0] || 'Unknown Error'
  41 + ss.log("! Unable to load #{file} on demand:".red, description)
  42 +
37 43
38 44 # Web Workers
39 45 worker = (request, response, path, cb) ->

0 comments on commit c784106

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