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

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Wed Feb 22 14:41:10 EST 2012

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.