nrstott / bogart Goto Github PK
View Code? Open in Web Editor NEWFast, Sinatra-Inspired JavaScript Framework running on JSGI with Node.JS!
Fast, Sinatra-Inspired JavaScript Framework running on JSGI with Node.JS!
I think that sums it up pretty well.
The purpose is to be able to write responses like this:
router.get('/', function (req) {
return bogart.html('Hello World', { headers: { 'set-cookie': [ 'foo=bar', 'bar=baz' ] } });
});
Jasmine is easier to read/use than node-tap. It is also more familiar to potential contributors.
Unify the Bogart story for authentication by creating a unified middleware (Vault) that has strategies for google+, facebook, and standard forms authentication.
I've tried
app = bogart.start(router,{port:80});
io = io.listen(app);
and receive
Error: EADDRINUSE, Address already in use
Any ideas?
I tried this in many different commits and broken pretty far back. I believe it broke during one of the changes to bogart.pipe
I think that the error handling by default should not only give you the stacktrace but give you the route as well if available.
Add support for serving index.html if it exists in a directory for a directory request handled by the directory middleware.
The batteries middleware does not support configuring its components.
Proposed format
{
directory: {
root: 'myroot',
headers: { ... }
},
error: {
formatter: function (err) { ... }
}
}
https://github.com/jahewson/node-deflate :)
Or perhaps there is already a way to do this with Bogart?
Currently bogart.router takes two paratmers, the first is a DSL configuration function that is run in the context of the router and the 2nd is the nextApp
function which is called when there is no route to handle the current route.
bogart.router should be changed to match standard JSGI middleware.
It should function such that bogart.router returns a function that takes a nextApp. That nextApp will be available as this.nextApp
perhaps to the route handlers to apply the russian doll model. req.nextApp
is also an option.
Example:
var router = bogart.router();
router.get('/', function(req) {
req.params['name'] = 'World';
return this.nextApp(req);
});
bogart.start(router(function() {
return function(req) {
return {
status: 200,
body: [ 'Hello ' + req.params.name ],
headers: { 'content-type': 'text/html' }
};
}
}));
Request:
GET / => 'Hello World'
No page gets displayed in the browser (at least Chrome), and the browser attempts to download the file.
For example, using:
var router = bogart.router();
var viewEngine = bogart.viewEngine('mustache');
router.get('/', function() {
return viewEngine.respond('page.html');
});
var Gzip = bogart.middleware.Gzip;
var app = Gzip(router);
bogart.start(app);
This could definitely be an implementation problem on my end, as I'm still a novice, but it seems like my bogart app is not receiving my JQuery ajax posts and gets properly.
On the client:
function queryFunc() {
$.get("query", function(response) {} )
.error(function(response, text, error) {
console.log("---Ajax Error---");
console.log(response);
console.log(text);
console.log(error);
});
}
On the server:
var bogart = require('bogart');
var viewEngine = bogart.viewEngine('mustache'),
router = bogart.router();
router.get('/query', function(req) {
console.log("Received get request.");
return bogart.redirect('moose/moose/moose');
});
var app = bogart.app();
app.use(bogart.batteries);
app.use(router);
app.start(8970, '127.0.0.1');
The server console doesn't get logged every time I make the ajax request, and the redirect response never goes through. The client logs an empty error response Object every time I make a call to queryFunc(). However, if I point my browser directly to /query, the redirect works as expected. The problem is similar with $.post() and router.post().
middleware.js, line 67 has require("zlib")
but zlib isn't setup as a dependency on the bogart npm package.
The parted middleware breaks convention with other bogart middleware by having its options be the secondary parameter and the nextApp the first. Change it so that the options come first and then nextApp is the last parameter.
Sorry to be a bother on this. Using the very latest bogart (0.3.7) I am still getting
Error: Cannot find module './deflate-bindings'
... when I run gzip-response.js.
I am on Ubuntu 11.04, bogart/node_modules/deflate is there, and I've successfully run build.sh in it.
Any ideas?
After installing bogart via npm it comes with a broken link:
bogart/node_modules/jsgi/lib/.#jsgi-node.js -> [email protected]:1307128011
view.js:
headers: opts.headers || { 'content-type': 'text/html', 'content-length': Buffer.byteLength(str, 'utf-8') }
I have 2 bogart apps running on the same domain and I a getting the following error:
An error occurred.
Message:
error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
Stack Trace:
TypeError: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
at Decipher.Cipher.final (crypto.js:287:27)
at Object.exports.decrypt (/sites/director-point/node_modules/bogart/lib/security.js:25:19)
at IdProvider.getSessionId (/sites/director-point/node_modules/bogart/lib/middleware/session/idProvider.js:27:23)
at /sites/director-point/node_modules/bogart/lib/middleware/session/session.js:50:32
at /sites/director-point/node_modules/bogart/lib/middleware/methodOverride.js:32:10
at /sites/director-point/node_modules/bogart/lib/middleware.js:21:14
at /sites/director-point/node_modules/bogart/lib/middleware/parted.js:25:14
at /sites/director-point/node_modules/bogart/lib/middleware/directory.js:97:16
at _fulfilled (/sites/director-point/node_modules/bogart/node_modules/q/q.js:703:54)
at self.promiseDispatch.done (/sites/director-point/node_modules/bogart/node_modules/q/q.js:732:30)
Bogart must live on! :)
When a developer forgets to return
the result of a promise-returning function call in a Bogart router, there is no useful error. The error is Not found: /insert/route/here
. This is because undefined is a valid return from a bogart router. The higher middleware, when batteries is included, is changing that to a 404 response.
However, this behavior is confusing, especially for newer users of Bogart.
It is important to keep the ability to return nothing for the use-case of writing middleware using routers; however, a new return should be indicated to signal intentionally empty.
This return could be a constant off of the bogart
namespace or it could be null.
Can someone please add to README.md a short paragraph on how to handle OPTIONS HTTP requests.
Hi,
I've tried to figure this out myself with no luck so far so can someone please help me understand how to send a cookie e.g. 'foo'='bar'. In the meantime I suppose I proxy to http and try setting the cookie there but it seems a bit of a waste.
BTW: In my efforts to try and figure it out, I see a lot of references to flash cookies but was unable to get supporting info from the web (also sorting it from adobe's flash made things harder). Same thing regarding JSGI where most info is understandable by those who already understand, not a noob like myself. Therefore, any suggestions for sources to help it sink in would be appreciated.
If this is not the correct place to be asking this type of question I apologize. If so, please direct me to where it would be more appropriate.
Many thanks!
In addition to supporting passing the function as a first-class parameter to form a middleware chain, make bogart middleware support calling it as a factory for returning the JSGI middleware.
Example:
app.use(bogart.middleware.parted); // current
app.use(bogart.middleware.parted()); // enhanced
This will permit middleware that requires parameters to be called more intuitively.
app.use(bogart.middleware.session, sessionConfig); // current
app.use(bogart.middleware.session(sessionConfig)); // enhanced
According to http://diveintohtml5.info/offline.html, html5 .manifest files should be served with a text/cache-manifest mimetype. I've had no trouble serving .manifest's with Bogart to Firefox, Safari, and Chrome, but I notice there is no mimetype for .manifest listed in lib/mimetypes.js. Maybe it should be added? Doesn't seem to be causing any problems though.
Many of the files that my "return bogart.html(article);" is serving up are truncated.
When I alternatively use:
return {
status: 200,
body: [article],
headers: { "content-type": "text/html", "content-length": article.length + 10 }
};
... substituting "10" for whatever you like, the web site response to the browser returns more text of "article", etc.
Hi,
I'm trying to load a partial into my main mustache template but fail with this message in the browser:
unknown_partial 'home_button.html'
My main template, index.html, looks like this:
<div>{{> home_button }}</div>
According to the mustache documentation I shouldn't need to add an extension, but I also tried {{> home_button.html }} and had no luck. My two template files live in the 'templates' directory. Any idea what I'm doing wrong?
Thanks,
Luke
ps: here's how I set up my bogart app
var bogart = require('bogart'),
path = require('path');
var app = bogart.router(function(get, post, put, del) {
var viewEngine = bogart.viewEngine('mustache', path.join(__dirname, 'templates'));
get('/', function(req) {
return viewEngine.respond('index.html');
});
/* ... snip ...*/
Hi,
I cannot send a response with the following:
This is the terminal output:
Trying to log in as barney
Posting to sessiondb , returned: '{"ok":true,"name":"barney","roles":["properties_reader"]}\n'
Success posting to session, returned AuthSessionAuthSession=YmFybmV5OjUxQkU1OTQ5Og7SxuLAcrLru-0aTPofOKno6-FR,Authrole=properties
reader
Testing credentials using cookie YmFybmV5OjUxQkU1OTQ5Og7SxuLAcrLru-0aTPofOKno6-FR
testCredentials: success
And the code goes like:
router.post('/authenticate', function(req) {
//post to couchdb with params.user/pswd to _sessions to get an AuthSession
return when(getResponse(options), function(response){
//get the AuthSession cookie, set req.session.authSession
//test the user against the target database
return when(testCredentials(options, req.session("AuthSession")), function(response){
})
}).then(function(){
var res = bogart.res();
res.status = 302;
res.headers = { "location": 'http://www.google.com'};
res.body = [];
res.end();
return res;
})
})
I never get a response.
What am I doing wrong?
router.get("/example", function(req){}, function(req){});
In order to insert validation or some other function into the pipeline prior to executing the actual route.
It's not the biggest deal, but I imagine it'll cause some frustration to others. I had to change
var viewEngine = bogart.viewEngine('mustache');
to
var viewEngine = bogart.viewEngine('mustache',__dirname + "/views");
It'd be nice to be able to have an option on the route to specify how long to cache server side for and whether or not to vary by param etc.
This could have memory leak implications. I'm not sure how you take those out of the programmers hands though unless you outsourced the actual cache to redis or something.
See https://github.com/nrstott/bogart#custom-http-verbs. Is the example missing a path param? Like so:
router.route('options', '/', function (req) {
// Logic for handling the request goes here.
});
router.get('/:article', function(req) {...})
supports:
RC_Sproul
but not
R.C._Sproul
The jade template engine requires the variable filename
to be set to the absolute path of the template file in order for includes to work right.
It's possible to achieve this within a route handler...
router.get('/', function() {
return viewEngine.respond('index.jade', { filename: path.join(__dirname,'/views/index.jade') });
});
...but that's kind of a pain. This could be solved a number of ways, but one way it can't is in the jade adapter. As implemented, bogart doesn't pass this information back to the template engine so when jade is added as a template engine it's rendering function can't automatically handle this.
As a solution to this, the viewEngine could pass the viewPath (along with the view and whatever else) back to the template engine for those engines that need it. I forked bogart and implemented this on my fork as a 5th parameter on the engine callback.
Where it was function(template, opts, cache, viewEngine)
It is now function(template, opts, cache, viewEngine, meta)
Does this sound like a solution that makes sense or is there a better approach?
https://github.com/tstone/bogart/commit/0df477cd822bc02ccaacf240657ca1d265df383f
https://github.com/tstone/bogart-jade/commit/5f9d943450d06f43e61ed7974d56feb131652e28
I followed the directions to setup bogart using npm. Copied the 'hello world' example into an app.js file and ran it with node. I get the error:
Cannot find module 'promised-io/lib/promise'
I assumed that npm would install promised-io as a dependency. Just in case I used npm to install 'promised-io' but it still generates the same error.
Add middleware for Google+ authentication using OAuth2.
This change will make it easier to test session data providers. It will also make bogart sessions more easily accessible to websocket servers.
This will also permit moving the logic for setting up the req.session function into the session middleware itself, simplifying non-default implementations of bogart session data providers.
Routing callbacks registered with before/after are currently executed without respect for any possible returned promises. We probably need shove the return values of all the before/after callbacks in to arrays and wait for a 'q.all' to resolve in the appropriate places.
Also, the 'after' callbacks should probably be executed after the promise from the call to "route.handler.apply" is resolved.
Thoughts?
/api/:client/dash-url
This is printed to my browser window when trying to navigate to a page hosted by the server:
An error occurred.Cannot change encoding
Stack Trace:
AssertionError: Cannot change encoding at getDecoder (crypto.js:241:3) at Decipher.Cipher.final (crypto.js:290:21) at Object.exports.decrypt (/Volumes/Macintosh HD/Users/bennlich/Documents/Node/cityknowledge/node_modules/bogart/lib/security.js:25:19) at CookieDataProvider.previousFlash (/Volumes/Macintosh HD/Users/bennlich/Documents/Node/cityknowledge/node_modules/bogart/lib/flash/flashCookieDataProvider.js:18:25) at /Volumes/Macintosh HD/Users/bennlich/Documents/Node/cityknowledge/node_modules/bogart/lib/middleware.js:392:62 at /Volumes/Macintosh HD/Users/bennlich/Documents/Node/cityknowledge/node_modules/bogart/lib/session/session.js:25:25 at exports.when (/Volumes/Macintosh HD/Users/bennlich/Documents/Node/cityknowledge/node_modules/promised-io/promise.js:348:29) at /Volumes/Macintosh HD/Users/bennlich/Documents/Node/cityknowledge/node_modules/bogart/lib/session/session.js:24:16 at /Volumes/Macintosh HD/Users/bennlich/Documents/Node/cityknowledge/node_modules/bogart/lib/middleware.js:126:16 at /Volumes/Macintosh HD/Users/bennlich/Documents/Node/cityknowledge/node_modules/bogart/lib/middleware.js:140:20
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.