Giter Site home page Giter Site logo

bones's Introduction

Bones

Bones provides conventions for Backbone applications. It allows most code to be shared on the server and the client. Bones exposes your Backbone 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.

Getting started

The wiki contains more information on Getting Started and on the concepts in Bones.

Example Application

Testing

To run the test suite, install mocha and type npm test.

Code coverages tests require jscoverage. To generate a report run npm run-script coverage.

License

Bones is BSD licensed.

bones's People

Contributors

dmitrig01 avatar kkaefer avatar lukemelia avatar makara avatar miccolis avatar tmcw avatar vkareh avatar wildintellect avatar willwhite avatar wrynearson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bones's Issues

Create/update should send back `resp` as payload

Let's talk about these commits:

The resp object is the proper object to send here and it is not correct to ignore it and send {} always when saving models. For an example case, backbone-couch expects to be able to inform the caller of the new _rev property of the document just saved and therefore returns that information as the resp object in sync.

See: https://github.com/developmentseed/backbone-couch/blob/master/backbone-couch.js#L65

support node v6 in 1.3 branch

This is needed for TileMill, since TileMill does not yet use bones 2.x.

This commit (3e3a0b6) was all that was needed since the latest express 2.x supports both node v4 and node v6.

Tests pass before and after this change with node v0.4.12 and after with node v.0.6.11.

Although we have a new warning with node v0.6.11:


(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace: 
    at [object Object].<anonymous> (events.js:139:15)
    at [object Object].once (events.js:160:8)
    at [object Object].listen (net.js:775:10)
    at Function.response (/usr/local/lib/node_modules/expresso/bin/expresso:424:16)
    at Test.fn (/Users/dane/projects/tilemill/node_modules/bones/test/collections.test.js:15:12)
    at Test.runParallel (/usr/local/lib/node_modules/expresso/bin/expresso:959:10)
    at Test.run (/usr/local/lib/node_modules/expresso/bin/expresso:924:18)
    at next (/usr/local/lib/node_modules/expresso/bin/expresso:867:22)
    at runSuite (/usr/local/lib/node_modules/expresso/bin/expresso:875:6)
    at check (/usr/local/lib/node_modules/expresso/bin/expresso:814:12)

Controller: Maintain backward compatibility

kkaefer: I saw that the response() callback was lost in a recent refactor - I put it back in:

e5823e4

I saw that you did some refactoring work here and I wonder what the intentions of your refactoring work are here...

Rename "Plugin"

"Plugin" is a confusing name, because the main app is a plugin, and a plugin is typically anything but the main app.

Alternate names:

  • server
  • app/application
  • instance
  • component

I'm sort of leaning towards instance: "Your bones application is comprised of multiple bones instances. For example, the application TileStream has instances of TileStream and Auth" or something like that.

Review max-age for mirror, static middleware

Before putting a Bones master site into production we'll want to review the max-age being set for mirrored assets and static files. These tend to default to 0 and nginx and other proxy caches simply won't cache for us if this is the case.

assets/bones/all.js fails to load

In server.prototype.initializeAssets (servers/Route.bones) the following needs to be changed:

-this.get('/assets/bones/all.js', this.assets.all);
+this.get('/assets/bones/all.js', this.assets.all.handler);

Otherwise any request to assets/bones/all.js gives the following error:

TypeError: string is not a function
at String.CALL_NON_FUNCTION (native)
at callbacks (/Users/william/Documents/workspaces/Sitemanager/UI/node_modules/bones/node_modules/express/lib/router/index.js:270:11)
at callbacks (/Users/william/Documents/workspaces/Sitemanager/UI/node_modules/bones/node_modules/express/lib/router/index.js:277:9)
at callbacks (/Users/william/Documents/workspaces/Sitemanager/UI/node_modules/bones/node_modules/express/lib/router/index.js:277:9)
at callbacks (/Users/william/Documents/workspaces/Sitemanager/UI/node_modules/bones/node_modules/express/lib/router/index.js:277:9)
at callbacks (/Users/william/Documents/workspaces/Sitemanager/UI/node_modules/bones/node_modules/express/lib/router/index.js:277:9)
at callbacks (/Users/william/Documents/workspaces/Sitemanager/UI/node_modules/bones/node_modules/express/lib/router/index.js:277:9)
at callbacks (/Users/william/Documents/workspaces/Sitemanager/UI/node_modules/bones/node_modules/express/lib/router/index.js:277:9)
at callbacks (/Users/william/Documents/workspaces/Sitemanager/UI/node_modules/bones/node_modules/express/lib/router/index.js:277:9)
at callbacks (/Users/william/Documents/workspaces/Sitemanager/UI/node_modules/bones/node_modules/express/lib/router/index.js:277:9)

Graceful restarts

We should make it possible to do graceful restarts of the http servers which bones starts. This is generally possible with node but it looks like as our servers in bones start after doing a bunch of synchronous work we've got a hole for incoming traffic. We'd need to figure out a strategy for the best way to make this possible.

Bones augment method is not working correctly

Taking a look at the example code, I noticed a flaw in the augment method.

If I debug the client model's 'sync' method, I get the arguments in the correct order:

method, model, options

If I augment the 'sync' method for the server version, I get an extra function as the first parameter (which was caused by '_.wrap'), rearranging the method signature, and leading to unexpected results:

func, method, model, options

sample app of bones using bones-auth and bones-admin

is there any complete sample app that uses these 2 plugins ? for instance against CouchDB ? I haven't found complete doc of bones, just 7 or 8 wiki pages but I think it is not enough. Tilestream app is too complex for newbies. IMO bones has a difficult learning curve. Thanks.

server side views won't work

Using the bones generated views on the server side won't work, because their provided jQuery context is not set. Selectors don't work that way.

I suggest that jQuery should be setup with a window and document for views.

Maybe I am overlooking something, but I've spent days already trying to tie into bones with server views. Too bad it doesn't work as expected.

Add Express Middleware to all servers

I want to add the Faceplate express middleware to a Bones project. I did by adding the code to server/middleware.bones & then calling it from servers/Middleware.bones. Is it possible to do something similar using a Plugin? I want Faceplate middleware to be run on the baseline Bones Server as opposed to creating a new server.

node v0.6 fails

Express 3.x (currently master) is required for node v.06 it appears.

Express 3.x removed its global HTTPServer so the usage of:

var HTTPServer = require('express').HTTPServer;

so bones/server.js fails:

~/projects/tilemill-node-v6[node-v6]$ ./index.js 
The "sys" module is now called "util". It should have a similar interface.

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Cannot read property 'prototype' of undefined
    at Object.<anonymous> (/Users/dane/projects/tilemill-node-v6/node_modules/bones/server/server.js:14:40)
    at Module._compile (module.js:432:26)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Module.require (module.js:357:17)
    at require (module.js:368:17)
    at Object.<anonymous> (/Users/dane/projects/tilemill-node-v6/node_modules/bones/bones.js:20:18)
    at Module._compile (module.js:432:26)
    at Object..js (module.js:450:10)

Consider changing `bones` suffix

I hate to bring this up, but I suspect we will be better off if we get our .bones suffixed files back into .js land. I've been using jscoverage on a bones project and I've had to hack it to instrument bones files. The change in the patch is very short but I think indicative of a class of problems that our custom file extension can create.

-  if (string_ends_with(file, ".js")) {
+  if (string_ends_with(file, ".js") || string_ends_with(file, ".bones")) {

Fragment handling for hash bang URLs

I just pushed a fix to fragment handling for hash bang URLs : 45becbc

Basically two things were broken:

  • the override to Backbone.history.saveLocation()
  • getFragment() stripped out the ! leading to mismatches of same URLs in checkUrl() (!/path != /path)

The fix brings extensive overrides to backbone which I'd rather avoid. The messiness stems from the fact that with hash bang (#!) URLs what's in the browser history (!/path) is different from the actual routes (/path) and thus non-JS fallbacks (http://example.com/path).

Allow contrib libraries to integrate into views/models/routers

as you know, in views/models/routers, there are a few pre-defined variables, like _, Bones, Backbone and they can be used in client side and server side.

But there is no way allow us add contrib library that like pre-defined variable in views/models/routers and share them on client and server side.

Do you have plan in future version ?

Routers not sent to client

I am using the 2.0.0 branch of Bones. If I have routers names: Default.bones & Default.server.bones, Default.bones does not get sent to the client, routers.js is an empty file. If I remove the server version, Default.bones gets passed in the router.js file. If I rename Default.server.bones to Other.server.bones, Default.bones gets executed on the server and passed to the client. How do I execute separate Routers on the server and client?

Allow isolating applications

There's no way of running more than one application in a node process. This is probably only relevant when writing test as expresso will load all test files into the main process. If there is more than one fixture, they will be merged together.

Connect now ships with CSRF middleware

This causes a crash:


node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
TypeError: Cannot set property csrf of #<Object> which has only a getter
    at Object.<anonymous> (/Users/kkaefer/node_modules/tilestream/node_modules/bones/server/middleware.js:39:17)
    at Module._compile (module.js:402:26)
    at Object..js (module.js:408:10)
    at Module.load (module.js:334:31)
    at Function._load (module.js:293:12)
    at require (module.js:346:19)
    at Object.<anonymous> (/Users/kkaefer/node_modules/tilestream/node_modules/bones/bones.js:11:22)
    at Module._compile (module.js:402:26)
    at Object..js (module.js:408:10)
    at Module.load (module.js:334:31)

Switch to underscore templates

kkaefer and I discussed removing the jade dependency from bones and just using underscore. The reasoning here is that in bones we're only using jade in the example, yet it adds a dependency to the project. We've already got underscore, and its minimal templating will work just fine for example purposes.

using partials

How should I use partials in bones views ? any example to follow up ? Wiki says: To invoke partials, use this'PartialName'. but where should I call it ?

Location for client-space singletons

Right now we hang client-space singletons like admin or user off of the Bones object - only client-side. Typically, a code like the snippet below is executed client-side to set up a global object, modules like bones-document would then rely on it.

$(function() {
    Bones.start();
    Bones.initialize(function(models, views, controllers, templates) {
        Bones.user = new models['User']();
        Bones.user.status(); 
        // ...

Two problems:

  1. This pattern cannot be replicated on the server as such global objects would be in the global application scope, not in the client (= window) scope.
  2. Having a global object X set up to make a module work as expected is not ideal, we should review better patterns (passing a user/admin/whatever object into constructors?)

Right now we're making hesitant use of the existing pattern described initially. If we solve this issue, we could make much safer assumptions around client space singletons and push more code into modules like bones-auth and bones-document = reuse more code.

Potential solutions

Bones could provide a 'request' object that would hang off an Express request server side and the window object client side. This 'request' object (better name?) would provide a safe space for client space objects.

More thoughts needed.

Always send a hash with a key 'error' containing a string on errors

Let me know what you think of this change.

I was not quite clear why sometimes next() was called and sometimes an error was sent by req.send().

The test for whether err is an Object is designed to ensure we're sending actually a string. This plays particularly well when err is an Error object (converts to the string that was passed in on construction).

46a2026

TypeError: Cannot set property csrf of [object Object] which has only a getter

after update express I got this error on bones application startup:

TypeError: Cannot set property csrf of # which has only a getter
at Object. (/Users/aldo/Satio/Desarrollo/express/satio-bones/node_modules/bones/server/middleware.js:39:17)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at require (module.js:346:19)
at Object. (/Users/aldo/Satio/Desarrollo/express/satio-bones/node_modules/bones/bones.js:11:22)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)

Checking middleware.js file I found csrf is being set when only get is allowed.

39 exports['csrf'] = function csrf() {
...
}

aldo@macbook ~/Satio/Desarrollo/express/satio-bones/node_modules/bones/node_modules/express > node

exports = module.exports = require('express');
{ basicAuth: [Getter],
bodyParser: [Getter],
compiler: [Getter],
cookieParser: [Getter],
csrf: [Getter],
version: '2.4.2',

Share models and resources between processes

Is there any way to share the models and current resources between different running processes of a same project?

The example would be:

  • start a bones app with the "start" command
  • in a separate terminal run a "cli" command (as defined in the /commands/ folder)

The goal would be to access through the CLI to the objects defined and running already via the start command. It seems not to be possible currently. Would you have any input on that part?

Some of the options I'd imagine is to execute the CLI command and get it to connect as a client (a la mysql) to a defined API allowing it to fetch some of the resources and get the CLI to process and the results.

Any insights would be appreciated.

Figure out template partials with Underscore 1.2.x

Our current system of using the this scope for handling template partials seems to be bust with underscore 1.2.2+ changes where this in the context of a template is no longer the templates object. We need a new approach or a way to repair the scope of our template functions back to the templates object.

If we do make a breaking change for this it should belong in 2.x with 1.x staying on underscore 1.x.

/cc @kkaefer @tmcw @willwhite

Remove attach()

The current approach of having client side only code in an attach() method that is triggered via backbone's event system only on the client is redundant with Bone's server side overrides (*.server.bones).

Remove it for Bones 2.x.

How to use bones without node?

Anyone knows how can i use bones as standalone js for my html pages? the functions like require() etc. does not work because i want to run it in a browser.

The example app leaks zombie App views

The bones example app creates a new App view for every view that subclasses Main. This leads to additional event handlers being attached and executing each time a new view displays. So while the example does work, it leaks resources in browser and isn't an ideal foundation for a real app.

There's a good description of the problem and one possible solution in the following link.

http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/

I'm sure this would take a knowledgeable bones / backbone developer only a little effort to fix, but as I'm new to both frameworks it took me a little time to figure out and fix the problem before I could move on to my own code.

Upgrade to backbone 0.9.1 and underscore 1.3.1

Hi - we've just put a few hours into upgrading our forked copy of bones to work with backbone 0.9.1 (latest) and underscore 1.3.1.

I'll attempt to add a patch to this comment, but the highlights follow below:

  1. Obviously the versions need to be bumped in Package.json
  •    "underscore": "1.1.x",
    
  •    "underscore": "1.3.x",
     "express": "2.4.4",
    
  •    "backbone": "0.5.1",
    
  •    "backbone": "0.9.1",
    
  1. in bones.js, set the server side jquery library into the imported backbone. Backbone now requires $ to be set, and the previous version was not loading it.

bones.js:
exports.Backbone = require('bones/server/backbone');
+exports.Backbone.setDomLibrary(exports.$);

  1. In plugin.js around lines 56/55 templates must now be passed to the client as a variable, as they're hidden using closure in the new _.template method.
  •            content: 'template = ' + module.exports + ';'
    
  •            // client must now pass escaped template content over, as _ makes it a hidden closure var
    
  •            content: 'var content = \''+escape(content)+'\';template = _.template(unescape(content));'
    

There are some changes to the example app that need to be made to work with these, but these 3 items are the show stoppers and only changes to the bones project core that we needed to make things work again. We made changes in our own app rather than updating the example, so unfortunately I can't share those, but the above should work as a leg up for anyone starting to upgrade the backbone version.

Can not set config in Server plugin.

using .augment() to override server/Router.bones initialize function and set this.enable('jsonp callback'), but it doesn't work.

I checked express code and found it use res.app.enabled('jsonp callback').

So, my issue is Bones can not set config in server plugin to http server.

Express 3.x

Hi,

What do you think about Express 3.x? Would you suggest upgrading to it if we could?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.