Replace this page with your favorite index page - how

The Racket Web Server makes use of a default index.html file that contains the following 2 lines:

Welcome to the Racket Web server! :

Please replace this page with your favorite index page.

Since relplacing the file is not sufficient to effect the change, I think it must be necessary force a re-compile - in some way.
Any recommendation?

Suppose you are running this:

#lang racket
(require web-server/servlet
         web-server/servlet-env)
 
(define (start req)
  (response/xexpr
   `(html (head (title "Hello world!"))
          (body (p "Hey out there!")))))
 
(serve/servlet start)

Then when you start the server on port 8000 and you go to localhost:8000/index.html, you see the page you mention. If you want to change that, you can set the #:server-root-path to another folder for serve/servlet:

#lang racket
(require web-server/servlet
         web-server/servlet-env)

(define (start req)
  (response/xexpr
   `(html (head (title "Hello world!"))
          (body (p "Hey out there!")))))

(serve/servlet start #:server-root-path "new-folder")

This folder should be in the same directory as the file that runs the server. As it says in the examples and documentation (1 Running Web Servlets), the web server will serve files from the 'htdocs' directory within 'new-folder', so you need to create an htdocs folder, and within that a new index.html. When you launch the web server, this new file is served -- but you may have to refresh the cache (hit F5 repeatedly, open private browser window and load page). Otherwise you may see the page simply because the browser cached it.

If you want the htdocs at the same level as your web server, use "./" for new-folder:

(serve/servlet start #:server-root-path "./")
1 Like