start.ss
#lang scheme/base
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SHP: Hypertext Processor
;;
;; a PHP like web framework for PLT Scheme
;;
;; Bonzai Lab, LLC.  All rights reserved.
;;
;; Licensed under LGPL.
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; start.ss
;; a default way of starting an SHP server, which combines both servlet.ss + web.ss
;; yc 8/23/2009 - first version 
;; yc 7/7/2010 - change start-shp-server to adapt to the new shp struct
(require web-server/servlet-env
         mzlib/etc
         )

(require (only-in web-server/servlet current-servlet-continuation-expiration-handler)
         web-server/managers/lru
         web-server/http/request-structs
         web-server/dispatchers/dispatch
         net/url
         mzlib/etc
         "main.ss" 
         "depend.ss" 
         )

(provide (all-defined-out))

(define interface-version 'v2)

(define manager
  (create-LRU-manager current-servlet-continuation-expiration-handler
                      60
                      3600
                      (lambda () #t)
                      #:initial-count 1 
                      #:inform-p (lambda _ (void))))

(define (start-shp-server! path 
                           #:htdocs (htdocs #f) 
                           #:port (port 8080)
                           #:default (default "index")
                           #:not-found (not-found #f)
                           #:required (required "/include/required")
                           #:topfilter (topfilter #f) 
                           #:chrome (chrome #f)) 
  (let ((shp (make-shp-handler path 
                               #:default default
                               ;; #:not-found not-found
                               #:required required 
                               #:topfilter topfilter
                               #:chrome chrome
                               #:htdocs htdocs)))
    (thread (lambda ()
              (serve/servlet shp
                             #:port port
                             #:servlet-path "/"
                             #:launch-browser? #f
                             #:listen-ip #f
                             #:servlet-namespace (list (path->string (this-expression-file-name)))
                             #:servlets-root path
                             #:servlet-regexp #px".*"
                             #:server-root-path path
                             #:extra-files-paths 
                             (list (cond ((not htdocs) 
                                          (build-path path 'up "file"))
                                         ((string? htdocs) (string->path htdocs))
                                         (else htdocs)))
                             )))
    shp))

 
#| ;; usage. 
(start-shp-server! (build-path (this-expression-source-directory) "shp")
                   #:htdocs (build-path (this-expression-source-directory) "file")
                   #:chrome "/include/chrome")
;;|#

;; (run! 8080 (build-path (this-expression-source-directory) "file"))