developmentseed / bones Goto Github PK
View Code? Open in Web Editor NEWA client/server web application framework built on Express and Backbone
License: BSD 3-Clause "New" or "Revised" License
A client/server web application framework built on Express and Backbone
License: BSD 3-Clause "New" or "Revised" License
"Plugin" is a confusing name, because the main app is a plugin, and a plugin is typically anything but the main app.
Alternate names:
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.
We should try to strip down the amount of data transferred on an initial page load.
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.
Will fix mapbox/tilemill#821
Is there any way to share the models and current resources between different running processes of a same project?
The example would be:
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.
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.
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)
The "sys" module is now called "util". It should have a similar interface.
kkaefer: I saw that the response() callback was lost in a recent refactor - I put it back in:
I saw that you did some refactoring work here and I wonder what the intentions of your refactoring work are here...
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.
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)
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',
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
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.
Setting the cookie in Safari fails silently, resulting in a 403 from the CSRF check middleware. The cookie is successfully set if the path
is removed.
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.
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)
Hi,
I don't think 2.1.x can be ready until developmentseed/mirror#3 is solved (let me know if I'm wrong).
Would you consider creating a 2.0
branch so we can submit some pull requests?
Thanks.
I just pushed a fix to fragment handling for hash bang URLs : 45becbc
Basically two things were broken:
!
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
).
sry, I was misinformed...
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();
// ...
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.
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.
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.
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")) {
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
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
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.
Hi,
What do you think about Express 3.x? Would you suggest upgrading to it if we could?
Thanks.
It seems they are unsync now after bones upgrade to backbone 0.5. Please confirm. Thanks.
After 0.5.x upgrade work was committed, what's missing for a 2.0 release?
I see a 1.3.22 at http://search.npmjs.org/#/bones but no tag here.
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?
hey, look at here: https://gist.github.com/1505400
I think the reason is the router of server side send the html to client side, but doesn't contains the views settings (such as events binding). Can you help me fix this issue ?
Rewrite tests using mocha.
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.
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 ?
These lines should be equivalent in Backbone:
this.$('.share-embed');
$('.share-embed', this.el);
But the this.$
form fails with https://gist.github.com/1134286
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).
Passing in the --config
option each time is a pain. We can come up with a sensible default location to check for a config file.
The module is unregistered from npm.
But that might be intentional because this package is unstable, right?
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 ?
We could support "virtual pageviews" for Google Analytics: http://code.google.com/apis/analytics/docs/tracking/asyncMigrationExamples.html#VirtualPageviews
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.
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)
I assumed require.js would be included in this module. Without it the server side code just won't be reusable I think.
As a matter of fact, I think the 'browserify' module should be used, to enable reuse of the 'templates' array on the client.
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:
"underscore": "1.1.x",
"underscore": "1.3.x",
"express": "2.4.4",
"backbone": "0.5.1",
"backbone": "0.9.1",
bones.js:
exports.Backbone = require('bones/server/backbone');
+exports.Backbone.setDomLibrary(exports.$);
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.
Express provides res.render()
. Investigate whether it makes sense to use in Bones.
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.
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.