commit 8173fe25eda45ed55d1b291de4c7620df2d07022 Author: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Mon May 29 20:12:44 2023 -0500 Init diff --git a/spidercat.scm b/spidercat.scm new file mode 100644 index 0000000..12c9edb --- /dev/null +++ b/spidercat.scm @@ -0,0 +1,65 @@ +;; +;; Copyright 2023, Jaidyn Levesque +;; +;; This program is free software: you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation, either version 3 of +;; the License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . +;; + +(import scheme + srfi-1 + (prefix chatdir chatdir:) + (prefix intarweb intarweb:) + (prefix spiffy spiffy:) + (prefix uri-common uri:)) + + +;; Handle all GET requests. +(define (get-handler irc-dir request continue) + (let ([path (uri:uri-path (intarweb:request-uri request))]) + (if (starts-with? path '(/)) + (spiffy:send-response status: 'ok body: "

Index ♥

") + (continue)))) + + +;; Handle all POST requests. +(define (post-handler irc-dir request continue) + (continue)) + + +;; Creates a handler for all HTTP requests, with the given IRC dir. +(define (make-http-handler irc-dir) + (lambda (continue) + (let* ([request (spiffy:current-request)] + [request-type (intarweb:request-method request)]) + (cond [(eq? request-type 'GET) + (get-handler irc-dir request continue)] + [(eq? request-type 'POST) + (post-handler irc-dir request continue)] + [#t + (intarweb:continue)])))) + + +;; Kick off the HTTP server. +(define (start-server irc-dir) + (spiffy:vhost-map `((".*" . ,(make-http-handler irc-dir)))) + (spiffy:start-server port: 8080)) + + +;; Check if a `list` begins with the elements of another list. +(define (starts-with? list list-start #!optional (= eq?)) + (list= = + (take list (length list-start)) + list-start)) + + + (start-server "/home/jaidyn/Chat/IRC/leagueh/")