Posted to tcl by Colin at Tue Jul 22 14:15:05 GMT 2008view raw

  1. #! /usr/bin/env tclsh
  2.  
  3. # Single Threaded Minimal File Server Site
  4. lappend auto_path [pwd] ;# path to the Site.tcl file
  5. namespace eval Site {
  6. variable varnish {}
  7. variable home [file dirname [info script]]
  8. }
  9.  
  10. package require Site
  11.  
  12. # This is a File domain which serves simple files
  13. # from the eponymous directory. Each file served has an expiry
  14. # date as indicated, which allows caching.
  15. File docroot -root $::Site::docroot
  16.  
  17. #### Incoming - handle of incoming request
  18. #
  19. # This proc is called with a fully parsed incoming request.
  20. # It uses Responder to act like tcl's [switch] command,
  21. # but wraps errors in an appropriate HTML response.
  22.  
  23. proc Incoming {req} {
  24. # [Responder Incoming] provides a safe wrapper and switch-like
  25. # dispatcher for incoming requests.
  26. return [Responder Incoming $req -glob -- [dict get $req -path] {
  27. / -
  28. /* {
  29. # redirect / to /wub
  30. docroot do $req
  31. }
  32. }]
  33. }
  34.  
  35. # Start Site Server(s)
  36. Site start
  37.