Re: [narwhal] Simple narwhal app engine example

3 views
Skip to first unread message

George Moschovitis

unread,
Dec 28, 2009, 4:18:09 AM12/28/09
to narw...@googlegroups.com, nitro...@googlegroups.com, appen...@googlegroups.com
Hello Peter,

The blog example uses jack, you can find some docs here: www.jackjs.org
Jack is similar to Rack and WSGI.

More specifically the example uses the Dispatch middleware (part of Nitro, www.nitrojs.org). The dispatching logic is simple:

For an incoming request path: /this/is/my/action?a=3

the Dispatcher loads the Jack application found in:

ROOT_DIRECTORY/this/is/my/action.js

action.js exports jack/jsgi application for each HTTP method, for example:

action.js:

exports.GET = function(env) {
    var params = new Request(env).params(),
         a = params.a;        
    ...
    return {status: 200, headers: {}, body: ["OK"]}
}

exports.POST = function(env) {
  ...
}

...

Nitro provides additional helpers to make this more programmer-friendly and support 'nicer' urls (sitemap).

If you want you can use another JSGI compatible framework like bogart (similar to sinatra).

Hope this helps,
-g.


On Mon, Dec 28, 2009 at 11:08 AM, Peter Svensson <psve...@gmail.com> wrote:
This is probably just me being in unfamiliar territory, but I'm trying to find some small piece of docs or code that shows just how to wire up routing of paths to different handlers in Narwhal.
I've got the blog example up and running and understand parts of it. My goal is to make a very simple app engine example that does not use server-side templating.

So what I wonder is basically where I define that '/foo?bar=baz' et.c. will be handled by xyzzy.js

Cheers,
PS

--
--------------------------------------------------------
http://se.linkedin.com/in/petersvensson

--

You received this message because you are subscribed to the Google Groups "Narwhal and Jack" group.
To post to this group, send email to narw...@googlegroups.com.
To unsubscribe from this group, send email to narwhaljs+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/narwhaljs?hl=en.



--
blog.gmosx.com

Peter Svensson

unread,
Dec 28, 2009, 4:23:47 AM12/28/09
to nitro...@googlegroups.com, narw...@googlegroups.com, appen...@googlegroups.com
Thanks George! That was just what I was looking for. Also it explains why I couldn't find any paths defined anywhere :)
I'll try to copy the whole blog example and let everything be where it is, and then strip it down to a minimal example.

Cheers,
PS

You received this message because you are subscribed to the Google Groups "nitro-devel" group.
To post to this group, send email to nitro...@googlegroups.com.
To unsubscribe from this group, send email to nitro-devel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nitro-devel?hl=en.



--
--------------------------------------------------------
http://se.linkedin.com/in/petersvensson

George Moschovitis

unread,
Dec 28, 2009, 5:23:17 AM12/28/09
to narw...@googlegroups.com, nitro...@googlegroups.com
Some more tips:

The Render middleware works in tandem with the Dispatcher middleware:

request path: /my/little/action
jsgi app: {ROOT}/my/little/action.js
template to render: {TEMPLATE_ROOT}/my/little/action.html

typically:

ROOT == src/root
TEMPLATE_ROOT = src/template

Please note that the Path middleware converts "/" to "/index"

some more info can be found here:


-g.





On Mon, Dec 28, 2009 at 11:26 AM, George Moschovitis <george.mo...@gmail.com> wrote:
Thanks George! That was just what I was looking for. Also it explains why I couldn't find any paths defined anywhere :)

Yeah, thats the concept behind the Dispatch middleware, the mappings are implicit in the filesystem.
(Though I have introduced the sitemap concept for additional functionality)

-g.
Reply all
Reply to author
Forward
0 new messages