GithubHelp home page GithubHelp logo

kieran / barista Goto Github PK

View Code? Open in Web Editor NEW
111.0 111.0 22.0 1.64 MB

A URL router / generator for NodeJS

Home Page: https://kieran.github.io/barista/

License: MIT License

JavaScript 56.36% CoffeeScript 43.35% Makefile 0.29%

barista's People

Contributors

abraxas avatar jbielick avatar jeansebtr avatar kieran avatar polotek avatar troyastorino 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

barista's Issues

Customizing Resources

A slightly exotic but I believe useful option, would be letting resources:

  • fetch parameters from the url match
  • dispatch to a custom controller (that does not correspond to the url)

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..

Error in barista 0.10

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)

Barista + express/connect

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.

Getting url from .url method by route_name

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?

wrong documentation

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?

What license is Barista?

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?

Method in router.first function is required. This is not comfortably.

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 about Strict Mode?

What i gotta do if i want strict mode? I need all the urls to end with /
For example /product/1/

broken mixin helper for deep copy

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 problem

router.resource('product');
/product/1/edit - Not mathced (false)
/products/1/edit - matched (true)
What to do? Is that feature or bug?

barista does not support a "bare" route

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.

Add request header routing

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'}})

Id parameter can not content dots

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?

Match periods with a glob

Sometimes I have filenames that have multiple periods in them. How can I have a glob that will also match periods?

Redirects

Is there a way to do redirects directly from the router?

Calling router.first method would return false when it takes URL which contains %20s ( spaces )

  • Steps to replicate this issue:
    1. 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');

    2. 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"}

  • Suggested Resolution:
    Modify the code on these following places:
    1. On Key.coffee line 16, line 93 & route.coffee line 10 => modify the regex so that it would recognise %20 (e.g. /[\w-%20]+/ ).
    2. Then on Route.coffee line 376 => get rid %20 on the part variable. The changes would be looked like this:
      // stash the pairings for loop 2
      pairings.push( [ segm, decodeURI(part) ] )

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.

Limiting the methods of the Resource class

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"]);

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.