bones
Advanced tools
Comparing version 1.2.5 to 1.2.6
{ | ||
"name": "bones", | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
@@ -5,0 +5,0 @@ "main": "./bones.js", |
@@ -1,66 +0,11 @@ | ||
Bones | ||
----- | ||
# Bones | ||
Conventions for server-side `backbone.js` views/controllers. Provides a set of | ||
overrides to allow the same Views and Controllers to be used both client-side | ||
and server-side. | ||
Bones provides conventions for [Backbone](http://documentcloud.github.com/backbone/) applications. It allows most code to be shared on the server and the client. Bones exposes your Backbone controller routes as regular paths on the server so they can be accessed by non-JavaScript agents, while capable clients can enjoy the normal client-side Backbone experience. | ||
+--------+ | ||
| Models | | ||
+-----------> +--------+ <------------+ | ||
| | Views | | | ||
| +--------------+ | | ||
| | Controllers | | | ||
| +--------------+ | | ||
+---------+ +---------+ | ||
| Browser | | Server | | ||
+---------+ +---------+ | ||
## Getting started | ||
Bones allows your Backbone controller routes to be served as normal static | ||
pages to crawlers and javascript-disabled browsers while allowing your users to | ||
enjoy the normal client-side Backbone experience. | ||
The [wiki](https://github.com/developmentseed/bones/wiki) contains more information on [**Getting Started**](https://github.com/developmentseed/bones/wiki/Getting-Started) and on the [concepts](https://github.com/developmentseed/bones/wiki/Plugin-Architecture) in Bones. | ||
## Getting started with Bones | ||
## License | ||
* Install node v0.4.* and npm 1.* | ||
* Create package.json file | ||
* Add bones as a bundleDependency/clone repo for development | ||
See https://github.com/developmentseed/skeleton for an example app that layout. | ||
### Application layout | ||
Bones expect you to organize your application in a certain way, and treats a few directories in special ways. | ||
* `/commands` - extra command line commands | ||
* `/controllers` - Backbone controllers | ||
* `/models` - Backbone models | ||
* `/routers` - server only routes | ||
* `/views` - Backbone views | ||
* `/servers` - applications | ||
* `/templates` - templates. | ||
With the exception of `/templates/` these directories will be populated with `.bones` files. Bones automatically adds the normal boilerplate stuff you would otherwise need to add to files suffixed with `.bones`. This has the additional benefit of not loading extra detection code to determine if the code is running on the server or client. Bones will simply add the right code. | ||
Files in each of these directories are expected to provide a single model|view|controller|template|etc... The file should be named as the class is name, capitalization is important! A `BlogPost` model should be defined in a `BlogPost.bones` file. | ||
### Creating an application | ||
Bones won't load new files automatically, you need to tell Bones to do that. Create a server by adding a file to `/servers`, and then register your models|views|controllers|templates|etc... The example application has an example server in `/bones/example/simple/server/main.bones`. | ||
Your application will need a entry point, an `index.js`. The example application again provides a good starting point here. | ||
Note, the second line of the file will need to be changed so that bones isn't included as using a relative path. Your application's `index.js` should say: | ||
var plugin = module.exports = require('bones').plugin(__dirname); | ||
## Extending bones | ||
* adding child modules (bones-document) | ||
* creating new components (.extend) vs. augmenting existing (.augment) | ||
* adding template engines (see bones/core/index.js) | ||
* server side vs. client side template compilation | ||
### Defining models & controllers | ||
Bones provdes default routes for loading models and collections. To take advantage of these endpoints your models and collections should implement a `url` method that returns a string of the form; `api/:collection` or `api/:model/:id`. The result of the `url` method is treated as the canonical resource identifier for that object. | ||
Bones is [BSD licensed](https://github.com/developmentseed/bones/raw/master/LICENSE). |
@@ -0,1 +1,3 @@ | ||
var env = process.env.NODE_ENV || 'development'; | ||
exports = module.exports = require('express'); | ||
@@ -11,3 +13,3 @@ | ||
} else { | ||
res.send(403); | ||
next(new Error.HTTP(403)); | ||
} | ||
@@ -30,1 +32,29 @@ } | ||
}; | ||
exports['showError'] = function showError() { | ||
return function showError(err, req, res, next) { | ||
if (!err.status) err.status = 500; | ||
if ((req.headers.accept + '' || '').indexOf('json') >= 0) { | ||
res.writeHead(err.status, { 'Content-Type': 'application/json' }); | ||
if (env === 'development') { | ||
res.end(JSON.stringify(err)); | ||
} else { | ||
res.end(JSON.stringify({ message: err.message })); | ||
} | ||
} else { | ||
res.writeHead(err.status, { 'Content-Type': 'text/plain' }); | ||
if (env === 'development') { | ||
res.end(err.stack); | ||
} else { | ||
res.end(err.message); | ||
} | ||
} | ||
}; | ||
}; | ||
exports['notFound'] = function notFound() { | ||
return function notFound(req, res, next) { | ||
next(new Error.HTTP(404)); | ||
}; | ||
}; |
@@ -24,2 +24,3 @@ var Backbone = require('./backbone'); | ||
this.initialize(plugin); | ||
this.conclude(plugin); | ||
}; | ||
@@ -43,4 +44,12 @@ | ||
this.server.use(middleware.fragmentRedirect()); | ||
this.server.error(middleware.showError()); | ||
}, | ||
// TODO: Find a better solution for pre/post hooks | ||
conclude: function(plugin) { | ||
if (this.server) { | ||
this.server.use(middleware.notFound()); | ||
} | ||
}, | ||
port: 3000, | ||
@@ -47,0 +56,0 @@ |
var utils = module.exports = require('../shared/utils'); | ||
var fs = require('fs'); | ||
var http = require('http'); | ||
var path = require('path'); | ||
@@ -80,1 +81,19 @@ var tty = require('tty'); | ||
}; | ||
Error.HTTP = function(message, status) { | ||
if (typeof message === 'number') { | ||
status = message; | ||
message = null; | ||
} | ||
if (!message) { | ||
message = http.STATUS_CODES[status] || 'Unknown'; | ||
} | ||
Error.call(this, message); | ||
Error.captureStackTrace(this, arguments.callee); | ||
this.message = message; | ||
this.status = status; | ||
}; | ||
Error.HTTP.prototype.__proto__ = Error.prototype; |
@@ -0,1 +1,2 @@ | ||
process.env.NODE_ENV = 'test'; | ||
var assert = require('assert'); | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
process.env.NODE_ENV = 'test'; | ||
var assert = require('assert'); | ||
@@ -65,3 +66,3 @@ | ||
}, { | ||
body: 'Cannot POST /page/foo', | ||
body: 'Not Found', | ||
status: 404 | ||
@@ -84,3 +85,3 @@ }); | ||
}, { | ||
body: 'Cannot GET /api/page/foo', | ||
body: 'Not Found', | ||
status: 404 | ||
@@ -87,0 +88,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
290097
94
1
8065
11
10
1