<commit_before>(defpackage :wookie-helper
  (:use :cl :wookie :wookie-plugin-export)
  (:export start-static-server))
(in-package :wookie-helper)

(defun start-static-server (&key (asset-dir "./") bind (port 8080))
  "This is a full-service convenience function that lets you quickly start up a
   server for serving static content (defaults to the current directory, but you
   can specify via `asset-dir`)."
  (load-plugins)
  (let ((*error-handler* (lambda (err socket)
                           (unless (typep err 'as:tcp-info)
                             (when (and socket (typep socket 'as:socket))
                               (let* ((socket-data (as:socket-data socket))
                                    (response (getf socket-data :response)))
                                 ;; if we've got a response object and an error hasn't been sent yet, send
                                 ;; one. this will fix 99.99% of client hanging. the other 0.01% has yet to
                                 ;; be discovered.
                                 (when (and response
                                            (not (response-finished-p response))
                                            (not (typep err 'auth-failed)))
                                   (let ((body (format nil "There was an error processing your request~a"
                                                       (if *display-errors*
                                                           (format nil ": ~a" err)
                                                           "."))))
                                     (send-response response :status 500 :body body)))))
                             ;; let the guy looking at the logs see.
                             (log:error "UNcaught error: ~a" err)))))
    (as:with-event-loop (:catch-app-errors t)
      (funcall (intern "DEF-DIRECTORY-ROUTE" :wookie-plugin-core-directory-router) "/" asset-dir)
      (let ((listener (make-instance 'listener :bind bind :port port)))
        (start-server listener)))))
<commit_msg>adding catch-all route to start-static-server<commit_after>(defpackage :wookie-helper
  (:use :cl :wookie :wookie-plugin-export)
  (:export start-static-server))
(in-package :wookie-helper)

(defun start-static-server (&key (asset-dir "./") bind (port 8080))
  "This is a full-service convenience function that lets you quickly start up a
   server for serving static content (defaults to the current directory, but you
   can specify via `asset-dir`)."
  (load-plugins)
  (let ((*error-handler* (lambda (err socket)
                           (unless (typep err 'as:tcp-info)
                             (when (and socket (typep socket 'as:socket))
                               (let* ((socket-data (as:socket-data socket))
                                    (response (getf socket-data :response)))
                                 ;; if we've got a response object and an error hasn't been sent yet, send
                                 ;; one. this will fix 99.99% of client hanging. the other 0.01% has yet to
                                 ;; be discovered.
                                 (when (and response
                                            (not (response-finished-p response))
                                            (not (typep err 'auth-failed)))
                                   (let ((body (format nil "There was an error processing your request~a"
                                                       (if *display-errors*
                                                           (format nil ": ~a" err)
                                                           "."))))
                                     (send-response response :status 500 :body body)))))
                             ;; let the guy looking at the logs see.
                             (log:error "UNcaught error: ~a" err)))))
    (funcall (intern "DEF-DIRECTORY-ROUTE" :wookie-plugin-core-directory-router) "/" asset-dir)
    ;; catch-all handler
    (defroute (:* ".*") (req res)
      (send-response res :status 404 :body "Not found!"))
    (as:with-event-loop (:catch-app-errors t)
      (let ((listener (make-instance 'listener :bind bind :port port)))
        (start-server listener)))))

{'fraction_non_alphanumeric': 0.10639793766112023, 'fraction_numerical': 0.0072650574173892665, 'mean_word_length': 1.307027027027027, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5577176', 'n_tokens_mistral': 1038, 'n_tokens_neox': 983, 'n_words': 344}