<commit_before>#lang scheme

(define default-context-length (error-print-context-length))

;; This code has parts that are copied from `serve/servlet' in
;; "web-server/servlet-env.ss", and parts from `serve/launch/wait' in
;; "web-server/servlet-dispatch.ss"

(require web-server/web-server
         web-server/servlet-dispatch
         web-server/managers/lru
         (prefix-in lift: web-server/dispatchers/dispatch-lift)
         (prefix-in fsmap: web-server/dispatchers/filesystem-map)
         (prefix-in sequencer: web-server/dispatchers/dispatch-sequencer)
         (prefix-in files: web-server/dispatchers/dispatch-files)
         (prefix-in log: web-server/dispatchers/dispatch-log)
         web-server/http/request-structs
         net/url
         net/tcp-sig
         net/ssl-tcp-unit)

(provide run-servlet)
(define (run-servlet dispatcher port server-dir
                     #:namespace [namespace '()]
                     #:log-file [log-file #f])
  (define ((send-error msg to) req)
    (let ([to (to)])
      `(html (head (meta ([http-equiv "refresh"]
                          [content ,(format "3;URL=~a" to)]))
                   (title ,msg))
             (body ,msg "; " (a ([href ,to]) "restarting") " in 3 seconds."))))
  (define tcp@
    (let ()
      (define-unit-binding ssl-tcp@
        (make-ssl-tcp@ (build-path server-dir "server-cert.pem")
                       (build-path server-dir "private-key.pem")
                       #f #f #f #f #f)
        (import) (export tcp^))
      ssl-tcp@))
  (serve
   #:port port #:listen-ip #f
   #:tcp@ tcp@
   #:dispatch
   (sequencer:make
    (and log-file (log:make #:format (log:log-format->format 'apache-default)
                            #:log-path log-file))
    (let ([init-path (make-parameter "/")])
      (dispatch/servlet
       (lambda (req)
         (init-path (url->string (request-uri req)))
         (dispatcher req))
       #:regexp #rx"^/(?:/|$)"
       #:namespace namespace
       #:current-directory server-dir
       #:manager (make-threshold-LRU-manager
                  (send-error "Your session has expired" init-path)
                  (* 12 1024 1024))))
    (files:make
     #:url->path (fsmap:make-url->path (build-path server-dir "htdocs")))
    (lift:make (send-error "File not found" (lambda () "/"))))))<commit_msg>Remove code that serves static files, it's not doing anything anyway if the servlet is used for all paths.<commit_after>#lang scheme

(define default-context-length (error-print-context-length))

;; This code has parts that are copied from `serve/servlet' in
;; "web-server/servlet-env.ss", and parts from `serve/launch/wait' in
;; "web-server/servlet-dispatch.ss"

(require web-server/web-server
         web-server/servlet-dispatch
         web-server/managers/lru
         (prefix-in sequencer: web-server/dispatchers/dispatch-sequencer)
         (prefix-in log: web-server/dispatchers/dispatch-log)
         web-server/http/request-structs
         net/url
         net/tcp-sig
         net/ssl-tcp-unit)

(provide run-servlet)
(define (run-servlet dispatcher port server-dir
                     #:namespace [namespace '()]
                     #:log-file [log-file #f])
  (define ((send-error msg to) req)
    (let ([to (to)])
      `(html (head (meta ([http-equiv "refresh"]
                          [content ,(format "3;URL=~a" to)]))
                   (title ,msg))
             (body ,msg "; " (a ([href ,to]) "restarting") " in 3 seconds."))))
  (define tcp@
    (let ()
      (define-unit-binding ssl-tcp@
        (make-ssl-tcp@ (build-path server-dir "server-cert.pem")
                       (build-path server-dir "private-key.pem")
                       #f #f #f #f #f)
        (import) (export tcp^))
      ssl-tcp@))
  (serve
   #:port port #:listen-ip #f
   #:tcp@ tcp@
   #:dispatch
   (sequencer:make
    (and log-file (log:make #:format (log:log-format->format 'apache-default)
                            #:log-path log-file))
    (let ([init-path (make-parameter "/")])
      (dispatch/servlet
       (lambda (req)
         (init-path (url->string (request-uri req)))
         (dispatcher req))
       #:regexp #rx""
       #:namespace namespace
       #:current-directory server-dir
       #:manager (make-threshold-LRU-manager
                  (send-error "Your session has expired" init-path)
                  (* 12 1024 1024))))
    ;; This can be used to serve html content too; doesn't make sense now,
    ;; since the servlet will be used for all requests.  (See "servlet-env.ss"
    ;; for the needed `require's)
    ;; (files:make
    ;;  #:url->path (fsmap:make-url->path (build-path server-dir "htdocs")))
    ;; (lift:make (send-error "File not found" (lambda () "/")))
    )))
{'fraction_non_alphanumeric': 0.15381373788453434, 'fraction_numerical': 0.0050568900126422255, 'mean_word_length': 2.1604527296937417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1868873', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1460, 'n_words': 365}