Specifying URLs

In the previous examples we've specified the full URL for each web page we've created; for example:

(export-url "http://localhost:8000/demo.html"
            :computed
            :response-function 'write-demo-page)

In a real application we would want our web site to be on a public domain, such as www.mydomain.com, and we would use DNS to map this domein name to the IP address of our server machine. The export-url command would then become:

(export-url "http://www.mydomain.com:8000/demo.html"
            :computed
            :response-function 'write-demo-page)

Specifying domain names portably

For flexibility CL-HTTP provides a #u reader macro, which allows you to omit the base domain name from the URLs you specify, so you can just write:

(export-url #u"/demo.html"
            :computed
            :response-function 'write-demo-page)

The full domain name is created using the DNS name and port for the server that CL-HTTP is running on. These are stored in the variables:

http::*local-host-domain-name*
http::*standard-http-port*

If the server has several domain names you can specify a particular one for the CL-HTTP server using *http-host-name*; for example:

(setq http:*http-host-name* "www.mydomain.com")

Serving several hosts from the same server

The #u reader macro has an extended syntax that allows you to overvride the default host and port specified by the server configuration. For more information see Virtual Hosting.


blog comments powered by Disqus