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

From: Gustavo Massaccesi (gustavo at oma.org.ar)
Date: Thu Feb 23 17:24:07 EST 2012

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.

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?


(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

Posted on the users mailing list.