Getting into appenginejs but skins and request routing have me stumped

10 views
Skip to first unread message

Greg

unread,
Oct 2, 2010, 5:30:19 PM10/2/10
to appenginejs
Hiya, so Ive just discovered appenginejs and am REALLY interested in
the potential for getting into SSJS. 2 main things have me scratching
my head though atm;



1) how do I use skinning/templates (i.e. I want to format a response
with a html template page)?

I initially followed the tutorial someone else posted here to
http://blog.obtiva.com/post/978165816/deploying-a-javascript-application-to-google-appengine
. I actually got skinning working but then became aware of the
appengine-blog-example and much preferred its structure and layout.
Trouble is, I cant get skinning to work with my own simple app (based
on appengine-example). I tried to do something like the following;

var Response = require('ringo/webapp/response');
...
exports.GET = function (request) {
return Response.skinResponse('templates/index.html', {});
}

but I get the error "No valid JSGI response"

I also tried the following as I saw it in the blog example;
var Response = require("nitro/response").Response;

but get the error "Wrapped java.io.IOException: Resource "nitro/
response" not found or not readable (main.js#4)"

what am I doing wrong?



2) Id like to have some request routing to a handler object based on
the incoming request;

The example at http://blog.obtiva.com/post/978165816/deploying-a-javascript-application-to-google-appengine
seemed to do just what I wanted with confg.js containing export.urls
and export.app but I cant see where these things are used + dont
understand why they dont seem to be used in appengine-blog-example and
ppengine-example



I guess the under-riding problem is I don't understand the differences
between these examples mentioned above? Are there any other tutorials/
docs apart from the api docs at ringojs.org, nitrojs.org and
appenginejs.org that can help get up to speed?

Cheers!,
Greg


gabriel munteanu

unread,
Oct 3, 2010, 6:35:57 AM10/3/10
to appen...@googlegroups.com
here is a tutorial that helped me a lot:
http://ringojs.org/wiki/Tutorial/

1).
specifically, when you wrote:
exports.GET ...
it should be :
exports.myurl.GET ...
and then you visit /myurl to see that in action.

2)
i am not sure how to do that, but my guess is that you want the whole
actions.js module
to be an object and do the handling there.
i am not sure what you want to accomplish, but the module actions.js
does just that well enough.
you just add actions:
example from a concrete app:
exports.index = ...
exports.contact = ...
exports.admin = ...
etc ...

check the tutorial above, it is really good.
cheers

--
jgabios
http://bash.editia.info

Greg

unread,
Oct 3, 2010, 6:02:25 PM10/3/10
to appenginejs
Thanks for the tutorial link - it was just what I was looking for!

So I think Ive figured out how to do what I want - in reverse order;

2) for the routing I first had my app.yaml with the following handler

handlers:
- url: /*
servlet: org.ringojs.jsgi.JsgiServlet
name: ringo
init_params:
module-path: src
config: main
app: app
optlevel: -1
ringo-home: /

which routes requests to main.js which contains something like;

exports.urls = [
['/', 'index']
,['/fred', 'fred']
];
exports.app = require('ringo/webapp').handleRequest;

hence requests for the the url /fred/<whatever> get routed to the fred
module - happy days!


1) for the skinning I just needed to do something like this;


var response = require('ringo/webapp/response');

exports.index = function (request) {
return exports[request.method](request);
}

exports.GET = function (request) {
return response.skinResponse('skins/index.html', {});
}


That seemed to do the trick - I think what caused problems for me was
trying to figure out the differences between the ringojs response and
the nitrojs response object (still not sure what the diff between them
is).

That exports.myurl.GET method of doing things looks neat too - I be
sure to look into that some more.

Cheers
Greg



On Oct 3, 11:35 am, gabriel munteanu <jajali...@gmail.com> wrote:
> here is a tutorial that helped me a lot:http://ringojs.org/wiki/Tutorial/
>
> >http://blog.obtiva.com/post/978165816/deploying-a-javascript-applicat...
> > . I actually got skinning working but then became aware of the
> > appengine-blog-example and much preferred its structure and layout.
> > Trouble is, I cant get skinning to work with my own simple app (based
> > on appengine-example). I tried to do something like the following;
>
> > var Response = require('ringo/webapp/response');
> > ...
> > exports.GET = function (request) {
> >        return Response.skinResponse('templates/index.html', {});
> > }
>
> > but I get the error "No valid JSGI response"
>
> > I also tried the following as I saw it in the blog example;
> > var Response = require("nitro/response").Response;
>
> > but get the error "Wrapped java.io.IOException: Resource "nitro/
> > response" not found or not readable (main.js#4)"
>
> > what am I doing wrong?
>
> > 2) Id like to have some request routing to a handler object based on
> > the incoming request;
>
> > The example athttp://blog.obtiva.com/post/978165816/deploying-a-javascript-applicat...
Reply all
Reply to author
Forward
0 new messages