[racket] Problem with default-indices files in Web-Server

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Feb 24 12:41:59 EST 2012

On Thu, Feb 23, 2012 at 3:24 PM, Gustavo Massaccesi <gustavo at oma.org.ar> wrote:
> Thanks for the answer. I prefer to use the standard plt-web-server
> executable, because I'm working in a small internal project for a few
> hundreds users. I solved my problem using a refresh in the index.html
> file to redirect the users to the real page. It isn't very elegant,
> but it works.

The standard executable is effectively deprecated. It will not support
new server features and it has not been getting new features for some
time. I consider the Web server to be a simple library for building
the server you need where a program is the effective configuration

> This message is more like a feature request for the plt-web-server:
> If I put a ".rkt" file, I expect to see the "result" from the
> execution of the servlet in the browser, not the source code. If I add
> "index.rkt" to the default-indices, I'm surprised, because I see the
> source code. Is it sensible to change the default behavior of the
> plt-web-server in this case?

I don't think this makes sense. If you go to a URL that matches the
servlet root (from the config file), then a servlet is executed. If
you go to a URL that matches the file root, then the file is served.
If the servlets are inside of the file directory (not the default and
probably a bad idea), then servlets can be viewed as source if their
execution is some how missed.


> Gustavo
> (If I add "index.gif" to the default-indices, the "index.gif" file is
> served as an image/gif file as expected. I don't know why someone
> would want to do that, but it works.)
> On Wed, Feb 22, 2012 at 16:41, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>> Indexes are used by the file server to turn a directory request into a
>> file request if the file exists.
>> What you want is some default behavior if there is no other handler
>> for a request, you could do that with a lift [1] dispatcher where the
>> procedure was just (lambda (req) (redirect-to "/index.rkt")) or
>> something that looked at the request's URL, found it to be a
>> directory, and then redirected to /index.rkt.
>> If you have your file server setup to serve a directory that contains
>> the servlet source, then if requests for those files get to it, then
>> they'll be served as source... because they are just files to that
>> code.
>> Jay
>> 1. Section 2.5 of the Web Server docs
>> On Tue, Feb 21, 2012 at 11:29 AM, Gustavo Massaccesi <gustavo at oma.org.ar> wrote:
>>> I wanted to make a 100% racket website (no html files), using the
>>> standard plt-web-server.exe (version 5.2.1, Windows). I need that all
>>> the pages are customized to each user.
>>> So I edited the configuration-table.rkt file to include the index.rkt
>>> in the list of default indices.
>>> ;--
>>> ;Edited File: configuration-table.rkt
>>> ( ...
>>>  (default-host-table
>>>   (host-table
>>>     (default-indices "index.rkt" "index.html" "index.htm")
>>>     ...))
>>>  ...)
>>> ;--
>>> For example, I use the example from
>>> http://docs.racket-lang.org/web-server/servlet.html as "index.rkt"
>>> (with (require web-server/http/xexpr)) in the web-root/htdoc
>>> directory, and launched the webserver.
>>> If I go to http://localhost/index.rkt , the example works as expected
>>> and I see the "Hi Mom!" message.
>>> But if I go to http://localhost/ , then I get the source code of the
>>> "index.rkt" file, something like.
>>> #lang racket (require web-server/managers/none) ... (...(...(...(body
>>> (h1 "Hi Mom!")))))
>>> but I expected to see only the "Hi Mom!" message.
>>> Now I'm using a index.htm file with a redirection:
>>> <meta http-equiv="REFRESH" content="1;url=/index.rkt">
>>> so the problem is almost solved.
>>> But I don't know if there is a better solution. Another problem is
>>> that the source code of the .rkt files may have some secret info that
>>> the users should not see (this is not my case).
>>> Gustavo
>>> ____________________
>>>  Racket Users list:
>>>  http://lists.racket-lang.org/users
>> --
>> Jay McCarthy <jay at cs.byu.edu>
>> Assistant Professor / Brigham Young University
>> http://faculty.cs.byu.edu/~jay
>> "The glory of God is Intelligence" - D&C 93

Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.