kieran / barista Goto Github PK
View Code? Open in Web Editor NEWA URL router / generator for NodeJS
Home Page: https://kieran.github.io/barista/
License: MIT License
A URL router / generator for NodeJS
Home Page: https://kieran.github.io/barista/
License: MIT License
A slightly exotic but I believe useful option, would be letting resources:
The case these try to solve is pretty URLs for categories of a single resource.
Say in a shop website, having /chairs/:id, /tables/:id, /beds/:id all dispatch to a Product controller with a type parameter to distinguish between them.
I imagine something in the lines of:
router.resource(':type','Products')
which would be pretty easy to implement - just provide the first parameter instead of #{slug} and the second parameter instead of #{controller} in the routes generated by the constructor. The methods of the controller would then have params.type available as whatever was between the slashes.
there might be a better syntax to make these optional and whatnot..
I need to submit a bugfix for v0.0.1, but there's no branch for it. Currently I've just monkeypatched the method inside of Geddy, but that's obviously disgusting. :)
Here is the stack trace of the error when trying to access a static file in Geddy:
TypeError: Object /staticfile.css has no method 'test'
at String.exports.Route.Route.parse (/Users/ben/Documents/geddy/node_modules/barista/lib/route.js:239:17)
at Router.exports.Router.Router.all (/Users/ben/Documents/geddy/node_modules/barista/lib/router.js:82:30)
at handleNoMatchedRoute (/Users/ben/Documents/geddy/lib/app/index.js:326:39)
at /Users/ben/Documents/geddy/lib/app/index.js:450:16
at b (domain.js:183:18)
at Domain.run (domain.js:123:23)
at Server. (/Users/ben/Documents/geddy/lib/app/index.js:398:11)
at Manager.handleRequest (/Users/ben/Documents/Toolkitt/node_modules/socket.io/lib/manager.js:565:28)
at Server. (/Users/ben/Documents/Toolkitt/node_modules/socket.io/lib/manager.js:119:10)
at Server.EventEmitter.emit (events.js:98:17)
Hey,
I've been reading about Barista has some hours now. It seems like a perfect router, but... how can I integrate it with express or connect?
Despite being programming node.js apps for a week now, I can't fully understand the routing system behind express :@ Is that possible at all?
Thanks in advance and sorry about my english.
Good day, Kieran, I use you library and find it very pretty and usefull, but every time I had one problem with URL generation โ if I had several rules witch dispatching to one action I can`nt generate correct URL for them.
For example:
router.get('/download/')
.to('download.index')
.name('download');
router.get('/download/:os/')
.to('download.index')
.name('download_os');
router.get('/download/:os/:type/')
.to('download.index')
.name('download_os_type');
And if I pass in template:
router.url({
controller: 'download',
action: 'index',
os: 'win'
})
I get "/download/" instead of "/download/win/", because rules for "/download/" defined above (
Maybe you add possibility to send string with route_name to .url method equally with pair controller + action?
the docs say the cllback after route matches is params
router.first( '/products/15', 'GET', function( params ){
// dispatch the request or something
})
but this is not true, it's actually
router.first( '/products/15', 'GET', function(undefined, params ){
// dispatch the request or something
})
i had to look to int the source to.
btw why should i care about undefined in the callback?
Can i generate URL by name?
Trying to sort out licensing for Geddy so that we can include a Geddy app in the Azure App Gallery. What license is Barista? I can't find any references to a license anywhere in the source.
Geddy is Apache 2: http://www.apache.org/licenses/LICENSE-2.0
Would it be possible to get some licensing info into the 0.1.x branch?
I need to route a single static file, like:
router.get('/admin').to('/admin.html');
Is it possible with barista?
You are impose to use different methods on different actions. I dont like this way. If i want to add a post to my blog i will use next way
/blog?action=create
Please, make method argument not required.
And one more issue. I think i found a safety hole in your router. I usualy require CSS and JS files in my HTML according to URL. So i'm making route
router.get( '/blog' )
.to( 'blog.show',{js:["/scripts/blog.js"]})
And i get js
key in object params
.
BUT if user make next URL
/blog?js=pathToBanner.js
Will i get this in params
?
What i gotta do if i want strict mode? I need all the urls to end with /
For example /product/1/
PATCH
was proposed in 2010, and has been widely adopted. Rails 4 uses it as the primary method for updates. It's nice to use, and so would be nice to support.
I noticed .to() can take a second paramter extra_params. It would be good if this was also available for .resource that would eventually get passed to their sub .to() calls.
Hi,
the mixin helper is broken for deep copy (it seems to alway have been) but, is it really necessary to use deep copy there ?
Here's a quick fix : https://github.com/JeanSebTr/barista/blob/v0.0.8-fix/lib/helpers.js#L21
I expect it won't be broken for next versions since they will be using coffe-script's mixin :)
Github doesn't allow to make a pull request on a tag. So, if you consider this enough to release a new version before the big rewrite, I would make a pull request against a 0.0.8 based branch.
router.resource('product');
/product/1/edit - Not mathced (false)
/products/1/edit - matched (true)
What to do? Is that feature or bug?
As on tin. I'd expect that a router should be able to handle a "/" route, just for convenience's sake.
At the very least, I'll try to abuse .defer for now to get things working.
It would be great if Barista allowed us to match routes based on the request's headers. It would help a lot when allowing custom domain support.
router.match('/').where({headers: {host: 'somesite.com'}})
It's sad!
i need an url like this
/sites/site.ru/edit
for my admin panel, but when i'm trying to generate this
router.get('/sites/:id/edit').to('sites.edit');
router.url({controller:'sites',action:'edit',id:'site.ru'})
I'm gettin '/sites/false/edit'
Please, tell me what to do?
Sometimes I have filenames that have multiple periods in them. How can I have a glob that will also match periods?
Is there a way to do redirects directly from the router?
Setup a URI template on Barista router:
var Barista = require('barista').Router;
var router = new Router;
router.post('/products/:productKeyScore/:vendor/*product(/)')
.to('products.update');
Call router's first method and pass a URL which contains spaces or %20s as its parameters.
var params = router.first("/products/1/Intel/Pentium MMX 233", 'POST');
Confirm that the 'params' var equals to false instead of this : {"method":"POST","controller":"products","action":"update","product":"Pentium MMX 233","vendor":"Intel","productKeyScore":"1"}
I hope this suggestion would make sense to you unless you have reasons why not allowing the regex to recognise %20 or spaces.
Many many thanks.
I need to store the information about what view to use in the routes.
And every day without this feature in the Barista Router one kitten is crying.
Are there any plans to add support for limiting the access points to a REST resource using something akin to Rails' only/except:
resources :posts do
resources :comments, only: [:index, :new, :create]
end
resources :photos, except: :destroy
An example would be:
router.resource("posts").only(["index","new","create"]);
router.resource("photos").except(["destroy"]);
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.