JSGI Example not working

1 view
Skip to first unread message

S.F.

unread,
Oct 14, 2009, 9:01:39 AM10/14/09
to Persevere
Hi,

I just figured out that the JSGI example at http://docs.persvr.org/documentation/server-side-js
(bottom) doesn't work the way it should.

The code is

app = function(env){
if(env["PATH_INFO"] == "somepath"){
return [200, {"Content-Type":"text/html"}, "<html><body>some
content</body></html>"];
}else{
return [404, {}, "Resource could be be found"];
}
};

But this returns an error when making a request to /somepath.
According to an example on jackjs.org it should be something like

app = function(env){
if(env["PATH_INFO"] == "/somepath"){
return {status:200, headers: {"Content-Type":"text/html"},
body: ["<html><body>some content</body></html>"]};
}else{
return {status:404, headers: {"Content-Type":"text/html"},
body: ["Resource could be be found"]};
}
};

An then it works when requesting /somepath. First you have to return
an object, not an array, and second the leading slash has to be
included when checking PATH_INFO.

Maybe someone can correct this. Thanks!

Regards,
S.F.

Vezquex

unread,
Nov 21, 2009, 4:59:00 AM11/21/09
to Persevere
I'm unclear as to where exactly the JSGI code goes. It would make a
good how-to.


On Oct 14, 5:01 am, "S.F." <stefan.fruehwi...@uni-graz.at> wrote:
> Hi,
>
> I just figured out that the JSGI example athttp://docs.persvr.org/documentation/server-side-js

Dean Landolt

unread,
Nov 22, 2009, 11:53:35 PM11/22/09
to persevere...@googlegroups.com
On Sat, Nov 21, 2009 at 4:59 AM, Vezquex <vez...@gmail.com> wrote:
I'm unclear as to where exactly the JSGI code goes. It would make a
good how-to.

There are two hooks for your JSGI code -- app and coreApp. I've never really explored the use of app (from what I understand it gets called after any 404 but I've never tested this assumption), but coreApp is a hook that allows you to inspect/override any request before it hits persvr's request filter. There are a few caveats (persvr doesn't completely respect every property you override, but it honors PATH_INFO and QUERY_STRING now, which is great) but it's still quite powerful to be able to intercept any request (for instance, if you must overwrite certain request properties you can just intercept the request and make a new HTTP request to localhost -- not the most efficient but it gets the job done).

What's your use case? Whatever it is there's a way to make it happen (even if it's not perfect), and there's a clear path to closer to perfection (pintura, or persvr 2.0...yay!).
Reply all
Reply to author
Forward
0 new messages