From c4a83be7477c2cc663bd529892629ee1ef58fc4a Mon Sep 17 00:00:00 2001 From: Dave Cooper Date: Sat, 20 Oct 2018 13:17:33 -0400 Subject: [PATCH 1/4] Made new subdirectory for test server code. Added other servers. --- Makefile | 24 +++- build.lisp | 2 + globals.lisp | 4 +- package.lisp | 6 +- servers/README.md | 110 ++++++++++++++++++ .../cl-http/cl-site-cl-http.asd | 15 ++- servers/cl-http/package.lisp | 5 + servers/cl-http/publish.lisp | 63 ++++++++++ servers/cl-http/serve.lisp | 21 ++++ servers/clack/cl-site-clack.asd | 15 +++ servers/clack/package.lisp | 5 + servers/clack/publish.lisp | 57 +++++++++ servers/clack/serve.lisp | 21 ++++ servers/htoot/cl-site-htoot.asd | 15 +++ servers/htoot/package.lisp | 5 + servers/htoot/publish.lisp | 57 +++++++++ servers/htoot/serve.lisp | 21 ++++ servers/paserve/cl-site-paserve.asd | 15 +++ servers/paserve/package.lisp | 5 + publish.lisp => servers/paserve/publish.lisp | 12 +- test-serve.lisp => servers/paserve/serve.lisp | 11 +- servers/woo/cl-site-woo.asd | 15 +++ servers/woo/package.lisp | 5 + servers/woo/publish.lisp | 57 +++++++++ servers/woo/serve.lisp | 21 ++++ servers/zaserve/cl-site-zaserve.asd | 15 +++ servers/zaserve/package.lisp | 4 + servers/zaserve/publish.lisp | 83 +++++++++++++ servers/zaserve/serve.lisp | 20 ++++ 29 files changed, 683 insertions(+), 26 deletions(-) create mode 100644 servers/README.md rename cl-site-test-serve.asd => servers/cl-http/cl-site-cl-http.asd (51%) create mode 100644 servers/cl-http/package.lisp create mode 100644 servers/cl-http/publish.lisp create mode 100644 servers/cl-http/serve.lisp create mode 100644 servers/clack/cl-site-clack.asd create mode 100644 servers/clack/package.lisp create mode 100644 servers/clack/publish.lisp create mode 100644 servers/clack/serve.lisp create mode 100644 servers/htoot/cl-site-htoot.asd create mode 100644 servers/htoot/package.lisp create mode 100644 servers/htoot/publish.lisp create mode 100644 servers/htoot/serve.lisp create mode 100644 servers/paserve/cl-site-paserve.asd create mode 100644 servers/paserve/package.lisp rename publish.lisp => servers/paserve/publish.lisp (87%) rename test-serve.lisp => servers/paserve/serve.lisp (57%) create mode 100644 servers/woo/cl-site-woo.asd create mode 100644 servers/woo/package.lisp create mode 100644 servers/woo/publish.lisp create mode 100644 servers/woo/serve.lisp create mode 100644 servers/zaserve/cl-site-zaserve.asd create mode 100644 servers/zaserve/package.lisp create mode 100644 servers/zaserve/publish.lisp create mode 100644 servers/zaserve/serve.lisp diff --git a/Makefile b/Makefile index f636cf8..2aa84fc 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,5 @@ all: build -serve: static favicon - sbcl --load test-serve.lisp - static: mkdir -p output/static @@ -12,3 +9,24 @@ build: static clean: rm -rf output mkdir output + +serve: paserve # May be swapped to others from time to time. + +paserve: static + sbcl --load servers/paserve/serve.lisp + +zaserve: static + sbcl --load servers/zaserve/serve.lisp + +htoot: static + sbcl --load servers/htoot/serve.lisp + +woo: static + sbcl --load servers/woo/serve.lisp + +clack: static + sbcl --load servers/clack/serve.lisp + +cl-http: static + sbcl --load servers/cl-http/serve.lisp + diff --git a/build.lisp b/build.lisp index 7e88635..e79c99c 100644 --- a/build.lisp +++ b/build.lisp @@ -3,6 +3,8 @@ (push (make-pathname :defaults *load-truename* :name nil :type nil) quicklisp:*local-project-directories*) +(ql:register-local-projects) + (ql:quickload :cl-site) (cl-site:make-site) diff --git a/globals.lisp b/globals.lisp index 9198499..14dcf10 100644 --- a/globals.lisp +++ b/globals.lisp @@ -37,5 +37,5 @@ wrapped with calls to add-content. Global value should always be nil.") -(defvar *aserve-port* 8008) -(defvar *aserve-listeners* 5) +(defvar *paserve-port* 8008) +;; FLAG add different ports for other webservers when activated diff --git a/package.lisp b/package.lisp index 19758a0..5752055 100644 --- a/package.lisp +++ b/package.lisp @@ -1,7 +1,11 @@ +(in-package :cl-user) + (defpackage #:cl-site (:use :cl) (:export #:make-site #:make-clean #:add-content #:wmd #:with-cl-who-string - #:start-aserve #:publish-cl-site)) + #:*output-dir* + #:*paserve-port* ;; FLAG export port globals for other webservers when activated + )) (defpackage #:cl-site-content diff --git a/servers/README.md b/servers/README.md new file mode 100644 index 0000000..e055288 --- /dev/null +++ b/servers/README.md @@ -0,0 +1,110 @@ +# Common-Lisp.net test webserver suite + +## Background + +Common Lisp Webservers have a long and storied history going back to +the beginning of the World Wide Web in the mid 1990s. CL servers and +frameworks continue to evolve rapidly today. + +There is a somewhat outdated list of CL webservers +[here](https://www.cliki.net/HTTP%20server). Consider volunteering to +help bring this list up to date. + + +## Purpose + +This set of directories is provided as a service to clnet volunteers +as well as a simple testbed for a variety of Common Lisp HTTP servers. + +Using the `serve.lisp` file in each of these directories, it should be +possible to start a local webserver which publishes the freshly built +local Common-Lisp.Net content and allows you to browse the site from +your local host. + + +## Support/Maintenance + +Note that the Common-Lisp.Net maintainers cannot commit to maintaining +all these webservers in guaranteed working order at all times. It is +expected that individual volunteers will be responsible for each +server (i.e. each subdirectory). + +Some of these subdirectories contain only stubs (i.e. placeholders) at +present, and if it represents a server you are interested in, please +consider volunteering to fill in the missing code and maintain that +server for the CLNet community. + +If there is a CL webserver which you care about or are curious about, +and it's not listed here, please feel free to add it. + + +## Usage + +### Command Line + +Use `make` followed by the desired server name. Currently existing +make targets are (note that many of these are still placeholders): + + make serve # starts a default server which is expected to work. + make clack # Aims to provide a server-agnostic veneer on top of any actual webserver. + make cl-http # The world's first HTTP1.1 server; powered whitehouse.gov under President Clinton. + make htoot # Hunchentoot (the "800lb Gorilla" of CL webservers). + make paserve # Legacy Portable AllegroServe (reverts to native aserve on Allegro CL). + make woo # The Fastest Webserver in the World. + make zaserve # the new "ZACL compatible" AllegroServe fork (reverts to native aserve on Allegro CL). + + +### From Lisp + +Load the following files to get the corresponding servers running from +within Lisp (note: if you try to do more than one at a time, your +mileage may vary. It'd be interesting though. Who can get them all +running at the same time (on distinct ports, of course, as defined +below) (substitute the path to your `cl-site/` direcotry for the +`...`): + + (load ".../cl-site/servers/clack/serve") + (load ".../cl-site/servers/cl-http/serve") + (load ".../cl-site/servers/htoot/serve") + (load ".../cl-site/servers/paserve/serve") + (load ".../cl-site/servers/woo/serve") + (load ".../cl-site/servers/zaserve/serve") + + + +## Directory structure + +(the following information will mainly be of interest if you want to +volunteer to maintain the code for one of the servers.) + +Each subdirectory should contain the following: + + +* `package.lisp` package definition for `:cl-site-`, + exporting `#:start-server` and `#:publish-cl-site` + +* `cl-site-.asd` should contain an ADSF system definition, + including `:depends-on` for the server in question. + +* `publish.lisp` should contain code in `:cl-site-` package, + defining the functions `publish-cl-site`, `client-test`, and + `start-server`. See completed examples and documentation in + placeholder code to see what these should do. + +* `serve.lisp` should load the `cl-site/build.lisp` file (which loads + core site content and renders it to output), then call the + corresponding servers's `start-server` and `publish-cl-site` + functions. Finally a message should be printed informing the + user how to visit the locally served site in their browser. + + +Finally, for each server there should be a corresponding distinct +default starting port number defined as a global parameter in +`cl-site/globals.lisp` with its symbol exported in +`cl-site/package.lisp` -- see existing one(s) for the expected +nomenclature. + + + + + diff --git a/cl-site-test-serve.asd b/servers/cl-http/cl-site-cl-http.asd similarity index 51% rename from cl-site-test-serve.asd rename to servers/cl-http/cl-site-cl-http.asd index 43f8055..ee4c7d2 100644 --- a/cl-site-test-serve.asd +++ b/servers/cl-http/cl-site-cl-http.asd @@ -1,16 +1,15 @@ ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- (in-package :cl-user) -(asdf:defsystem cl-site-test-serve - :name "cl-site-test-serve" +(asdf:defsystem cl-site-cl-http + :name "cl-site-cl-http" :version "0.0.1" :maintainer "Common-Lisp.Net maintainers" :author "Dave Cooper & Common-Lisp.Net maintainers" :licence "TBD" - :description "Test server for common-lisp.net, written in CL" - :depends-on (:cl-site :aserve) - :components ((:module source - :pathname "" - :serial t - :components ((:file "publish"))))) + :description "Test server for common-lisp.net for cl-http" + :depends-on (:cl-site) ;; :cl-http ;; FLAG -- add cl-http when/if available in Quicklisp. + :serial t + :components ((:file "package") + (:file "publish"))) diff --git a/servers/cl-http/package.lisp b/servers/cl-http/package.lisp new file mode 100644 index 0000000..454bb98 --- /dev/null +++ b/servers/cl-http/package.lisp @@ -0,0 +1,5 @@ +(in-package :cl-user) + +(defpackage #:cl-site-cl-http + (:use :cl) + (:export #:start-server #:publish-cl-site)) diff --git a/servers/cl-http/publish.lisp b/servers/cl-http/publish.lisp new file mode 100644 index 0000000..6afab00 --- /dev/null +++ b/servers/cl-http/publish.lisp @@ -0,0 +1,63 @@ +(in-package :cl-site-cl-http) + +(defparameter *listeners* 5) + +(defun print-unimplemented-message () + (format t " + +********************************** + +Thank you for trying the clnet site cl-Http test server! + +cl-http itself is not available in Quicklisp so it is not loaded +yet. So, the first step would be to get it added to Quicklisp (Reinier +Joswig might be able to help with this; when it's fit for inclusion, +you can make a request at + + https://github.com/quicklisp/quicklisp-projects/issues + +Next, the specific code for serving the cl-site pages for cl-http has +not been filled in yet. + +If you'd like to volunteer to do this, and maintain it, please fill in +the `publish-cl-site,' `client-test,' and `start-server' functions in +the file cl-site/servers/cl-http/publish.lisp. + +Any changes/additions for cl-http support should be contained in +this directory (cl-site/servers/cl-http/), except for the definition and +exporting of a global variable specifying a distinct cl-http +default starting port `cl-site-cl-http:*port*,' which can go in +cl-site/globals.lisp and cl-site/package.lisp respectively. + + +For implementing the functions below, it may help to follow the +examples in cl-site/servers/paserve/publish.lisp. + +********************************** + +")) + + +(defun publish-cl-site (&key (output-dir cl-site:*OUTPUT-DIR*)) + "This function should publish all the site content from the output-dir, both with and without their .html suffices" + (declare (ignore ouput-dir))) + + +(defun client-test (port) + "This function should check whether the given port is free for listening, and return it if so, nil if not." + (declare (ignore port))) + + +(defun start-server (&key (port ;;cl-site:*cl-http-port* ;; FLAG Define this global and uncomment this when activated. + ) (listeners *listeners*)) + "This function should check for the next available port, starting with the given port, and start a webserver +on that port. If starting on that port throws an error, then subsequent ports should be tried, with randomly +increasing wait times in between (a la Ethernet collision avoidance strategy)." + (declare (ignore port listeners)) + (print-unimplemented-message)) + + + + + + diff --git a/servers/cl-http/serve.lisp b/servers/cl-http/serve.lisp new file mode 100644 index 0000000..ec62439 --- /dev/null +++ b/servers/cl-http/serve.lisp @@ -0,0 +1,21 @@ +(in-package :cl-user) + +(uiop:with-current-directory (*load-truename*) + (load "../../build")) + +(ql:quickload :cl-site-cl-http) + +;; +;; Start aserve, publish site directory & pages, set default package. +;; +(cl-site-cl-http:start-server) +(cl-site-cl-http:publish-cl-site) +(setq *package* (find-package :cl-site)) + +(format t " + +This message from cl-site/servers/cl-http/serve.lisp should report the url & port +that the user may visit to browse the site. + +") + diff --git a/servers/clack/cl-site-clack.asd b/servers/clack/cl-site-clack.asd new file mode 100644 index 0000000..3043b9e --- /dev/null +++ b/servers/clack/cl-site-clack.asd @@ -0,0 +1,15 @@ +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- +(in-package :cl-user) + +(asdf:defsystem cl-site-clack + :name "cl-site-clack" + :version "0.0.1" + :maintainer "Common-Lisp.Net maintainers" + :author "Dave Cooper & Common-Lisp.Net maintainers" + :licence "TBD" + :description "Test server for common-lisp.net for Clack" + :depends-on (:cl-site :clack) + :serial t + :components ((:file "package") + (:file "publish"))) + diff --git a/servers/clack/package.lisp b/servers/clack/package.lisp new file mode 100644 index 0000000..f69fac7 --- /dev/null +++ b/servers/clack/package.lisp @@ -0,0 +1,5 @@ +(in-package :cl-user) + +(defpackage #:cl-site-clack + (:use :cl) + (:export #:start-server #:publish-cl-site)) diff --git a/servers/clack/publish.lisp b/servers/clack/publish.lisp new file mode 100644 index 0000000..f86a7e0 --- /dev/null +++ b/servers/clack/publish.lisp @@ -0,0 +1,57 @@ +(in-package :cl-site-clack) + +(defparameter *listeners* 5) + +(defun print-unimplemented-message () + (format t " + +********************************** + +Thank you for trying the clnet site Clack test server! + +Clack itself is loaded and ready to go! But, the specific code +for serving the cl-site pages for Clack has not been filled in +yet. + +If you'd like to volunteer to do this, and maintain it, please fill in +the `publish-cl-site,' `client-test,' and `start-server' functions in +the file cl-site/servers/clack/publish.lisp. + +Any changes/additions for Clack support should be contained in +this directory (cl-site/servers/clack/), except for the definition and +exporting of a global variable specifying a distinct Clack +default starting port `cl-site-clack:*port*,' which can go in +cl-site/globals.lisp and cl-site/package.lisp respectively. + + +For implementing the functions below, it may help to follow the +examples in cl-site/servers/paserve/publish.lisp. + +********************************** + +")) + + +(defun publish-cl-site (&key (output-dir cl-site:*OUTPUT-DIR*)) + "This function should publish all the site content from the output-dir, both with and without their .html suffices" + (declare (ignore ouput-dir))) + + +(defun client-test (port) + "This function should check whether the given port is free for listening, and return it if so, nil if not." + (declare (ignore port))) + + +(defun start-server (&key (port ;;cl-site:*clack-port* ;; FLAG Define this global and uncomment this when activated. + ) (listeners *listeners*)) + "This function should check for the next available port, starting with the given port, and start a webserver +on that port. If starting on that port throws an error, then subsequent ports should be tried, with randomly +increasing wait times in between (a la Ethernet collision avoidance strategy)." + (declare (ignore port listeners)) + (print-unimplemented-message)) + + + + + + diff --git a/servers/clack/serve.lisp b/servers/clack/serve.lisp new file mode 100644 index 0000000..6547f56 --- /dev/null +++ b/servers/clack/serve.lisp @@ -0,0 +1,21 @@ +(in-package :cl-user) + +(uiop:with-current-directory (*load-truename*) + (load "../../build")) + +(ql:quickload :cl-site-clack) + +;; +;; Start aserve, publish site directory & pages, set default package. +;; +(cl-site-clack:start-server) +(cl-site-clack:publish-cl-site) +(setq *package* (find-package :cl-site)) + +(format t " + +This message from cl-site/servers/clack/serve.lisp should report the url & port +that the user may visit to browse the site. + +") + diff --git a/servers/htoot/cl-site-htoot.asd b/servers/htoot/cl-site-htoot.asd new file mode 100644 index 0000000..733198f --- /dev/null +++ b/servers/htoot/cl-site-htoot.asd @@ -0,0 +1,15 @@ +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- +(in-package :cl-user) + +(asdf:defsystem cl-site-htoot + :name "cl-site-htoot" + :version "0.0.1" + :maintainer "Common-Lisp.Net maintainers" + :author "Dave Cooper & Common-Lisp.Net maintainers" + :licence "TBD" + :description "Test server for common-lisp.net for Hunchentoot" + :depends-on (:cl-site :hunchentoot) + :serial t + :components ((:file "package") + (:file "publish"))) + diff --git a/servers/htoot/package.lisp b/servers/htoot/package.lisp new file mode 100644 index 0000000..1008422 --- /dev/null +++ b/servers/htoot/package.lisp @@ -0,0 +1,5 @@ +(in-package :cl-user) + +(defpackage #:cl-site-htoot + (:use :cl) + (:export #:start-server #:publish-cl-site)) diff --git a/servers/htoot/publish.lisp b/servers/htoot/publish.lisp new file mode 100644 index 0000000..fedc489 --- /dev/null +++ b/servers/htoot/publish.lisp @@ -0,0 +1,57 @@ +(in-package :cl-site-htoot) + +(defparameter *listeners* 5) + +(defun print-unimplemented-message () + (format t " + +********************************** + +Thank you for trying the clnet site Hunchentoot test server! + +Hunchentoot itself is loaded and ready to go! But, the specific code +for serving the cl-site pages for Hunchentoot has not been filled in +yet. + +If you'd like to volunteer to do this, and maintain it, please fill in +the `publish-cl-site,' `client-test,' and `start-server' functions in +the file cl-site/servers/htoot/publish.lisp. + +Any changes/additions for Hunchentoot support should be contained in +this directory (cl-site/servers/htoot/), except for the definition and +exporting of a global variable specifying a distinct Hunchentoot +default starting port `cl-site-htoot:*port*,' which can go in +cl-site/globals.lisp and cl-site/package.lisp respectively. + + +For implementing the functions below, it may help to follow the +examples in cl-site/servers/paserve/publish.lisp. + +********************************** + +")) + + +(defun publish-cl-site (&key (output-dir cl-site:*OUTPUT-DIR*)) + "This function should publish all the site content from the output-dir, both with and without their .html suffices" + (declare (ignore ouput-dir))) + + +(defun client-test (port) + "This function should check whether the given port is free for listening, and return it if so, nil if not." + (declare (ignore port))) + + +(defun start-server (&key (port ;;cl-site:*htoot-port* ;; FLAG Define this global and uncomment this when activated. + ) (listeners *listeners*)) + "This function should check for the next available port, starting with the given port, and start a webserver +on that port. If starting on that port throws an error, then subsequent ports should be tried, with randomly +increasing wait times in between (a la Ethernet collision avoidance strategy)." + (declare (ignore port listeners)) + (print-unimplemented-message)) + + + + + + diff --git a/servers/htoot/serve.lisp b/servers/htoot/serve.lisp new file mode 100644 index 0000000..71b49b2 --- /dev/null +++ b/servers/htoot/serve.lisp @@ -0,0 +1,21 @@ +(in-package :cl-user) + +(uiop:with-current-directory (*load-truename*) + (load "../../build")) + +(ql:quickload :cl-site-htoot) + +;; +;; Start aserve, publish site directory & pages, set default package. +;; +(cl-site-htoot:start-server) +(cl-site-htoot:publish-cl-site) +(setq *package* (find-package :cl-site)) + +(format t " + +This message from cl-site/servers/htoot/serve.lisp should report the url & port +that the user may visit to browse the site. + +") + diff --git a/servers/paserve/cl-site-paserve.asd b/servers/paserve/cl-site-paserve.asd new file mode 100644 index 0000000..e239491 --- /dev/null +++ b/servers/paserve/cl-site-paserve.asd @@ -0,0 +1,15 @@ +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- +(in-package :cl-user) + +(asdf:defsystem cl-site-paserve + :name "cl-site-paserve" + :version "0.0.1" + :maintainer "Common-Lisp.Net maintainers" + :author "Dave Cooper & Common-Lisp.Net maintainers" + :licence "TBD" + :description "Test server for common-lisp.net for Legacy Portable AllegroServe" + :depends-on (:cl-site :aserve) ;; FLAG system name may be updated to :paserve in future QL. + :serial t + :components ((:file "package") + (:file "publish"))) + diff --git a/servers/paserve/package.lisp b/servers/paserve/package.lisp new file mode 100644 index 0000000..d97637a --- /dev/null +++ b/servers/paserve/package.lisp @@ -0,0 +1,5 @@ +(in-package :cl-user) + +(defpackage #:cl-site-paserve + (:use :cl) + (:export #:start-server #:publish-cl-site)) diff --git a/publish.lisp b/servers/paserve/publish.lisp similarity index 87% rename from publish.lisp rename to servers/paserve/publish.lisp index 2274cc4..eab5727 100644 --- a/publish.lisp +++ b/servers/paserve/publish.lisp @@ -1,15 +1,15 @@ -(in-package :cl-site) +(in-package :cl-site-paserve) +(defparameter *listeners* 5) -(defun publish-cl-site () - - (dolist (file (directory (make-pathname :defaults *OUTPUT-DIR* :name :wild :type "html"))) +(defun publish-cl-site (&key (output-dir cl-site:*OUTPUT-DIR*)) + (dolist (file (directory (make-pathname :defaults output-dir :name :wild :type "html"))) (dolist (format-string (list "/~a" "/~a.htm" "/~a.html")) (net.aserve:publish-file :path (format nil format-string (pathname-name file)) :file (namestring file)))) (net.aserve:publish-directory :prefix "/" - :destination (namestring *output-dir*))) + :destination (namestring output-dir))) ;; @@ -51,7 +51,7 @@ -(defun start-aserve (&key (port *aserve-port*) (listeners *aserve-listeners*) +(defun start-server (&key (port cl-site:*paserve-port*) (listeners *listeners*) ;; ;; FLAG -- figure out correct external-format for the other Lisps. ;; diff --git a/test-serve.lisp b/servers/paserve/serve.lisp similarity index 57% rename from test-serve.lisp rename to servers/paserve/serve.lisp index e265cfa..71de8b9 100644 --- a/test-serve.lisp +++ b/servers/paserve/serve.lisp @@ -1,20 +1,19 @@ (in-package :cl-user) (uiop:with-current-directory (*load-truename*) - (load "build")) + (load "../../build")) -(ql:quickload :cl-site-test-serve) +(ql:quickload :cl-site-paserve) ;; -;; Start aserve, publish site directory & pages, set default package. +;; Start paserve, publish site directory & pages, set default package. ;; -(cl-site:start-aserve) -(cl-site:publish-cl-site) +(cl-site-paserve:start-server) +(cl-site-paserve:publish-cl-site) (setq *package* (find-package :cl-site)) (let ((wserver net.aserve:*wserver*)) (when wserver - ;; FLAG replace with `usocket:get-local-port` after upgrading to zaserve. (let ((port (acl-compat.socket::port(net.aserve:wserver-socket wserver)))) (format t "You may now visit http://localhost:~a to test the site.~%" port)))) diff --git a/servers/woo/cl-site-woo.asd b/servers/woo/cl-site-woo.asd new file mode 100644 index 0000000..b8cc3a2 --- /dev/null +++ b/servers/woo/cl-site-woo.asd @@ -0,0 +1,15 @@ +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- +(in-package :cl-user) + +(asdf:defsystem cl-site-woo + :name "cl-site-woo" + :version "0.0.1" + :maintainer "Common-Lisp.Net maintainers" + :author "Dave Cooper & Common-Lisp.Net maintainers" + :licence "TBD" + :description "Test server for common-lisp.net for Woo" + :depends-on (:cl-site :woo) + :serial t + :components ((:file "package") + (:file "publish"))) + diff --git a/servers/woo/package.lisp b/servers/woo/package.lisp new file mode 100644 index 0000000..7d0aa3e --- /dev/null +++ b/servers/woo/package.lisp @@ -0,0 +1,5 @@ +(in-package :cl-user) + +(defpackage #:cl-site-woo + (:use :cl) + (:export #:start-server #:publish-cl-site)) diff --git a/servers/woo/publish.lisp b/servers/woo/publish.lisp new file mode 100644 index 0000000..392bda7 --- /dev/null +++ b/servers/woo/publish.lisp @@ -0,0 +1,57 @@ +(in-package :cl-site-woo) + +(defparameter *listeners* 5) + +(defun print-unimplemented-message () + (format t " + +********************************** + +Thank you for trying the clnet site Woo test server! + +Woo itself is loaded and ready to go! But, the specific code +for serving the cl-site pages for Woo has not been filled in +yet. + +If you'd like to volunteer to do this, and maintain it, please fill in +the `publish-cl-site,' `client-test,' and `start-server' functions in +the file cl-site/servers/woo/publish.lisp. + +Any changes/additions for Woo support should be contained in +this directory (cl-site/servers/woo/), except for the definition and +exporting of a global variable specifying a distinct Woo +default starting port `cl-site-woo:*port*,' which can go in +cl-site/globals.lisp and cl-site/package.lisp respectively. + + +For implementing the functions below, it may help to follow the +examples in cl-site/servers/paserve/publish.lisp. + +********************************** + +")) + + +(defun publish-cl-site (&key (output-dir cl-site:*OUTPUT-DIR*)) + "This function should publish all the site content from the output-dir, both with and without their .html suffices" + (declare (ignore ouput-dir))) + + +(defun client-test (port) + "This function should check whether the given port is free for listening, and return it if so, nil if not." + (declare (ignore port))) + + +(defun start-server (&key (port ;;cl-site:*woo-port* ;; FLAG Define this global and uncomment this when activated. + ) (listeners *listeners*)) + "This function should check for the next available port, starting with the given port, and start a webserver +on that port. If starting on that port throws an error, then subsequent ports should be tried, with randomly +increasing wait times in between (a la Ethernet collision avoidance strategy)." + (declare (ignore port listeners)) + (print-unimplemented-message)) + + + + + + diff --git a/servers/woo/serve.lisp b/servers/woo/serve.lisp new file mode 100644 index 0000000..c88328d --- /dev/null +++ b/servers/woo/serve.lisp @@ -0,0 +1,21 @@ +(in-package :cl-user) + +(uiop:with-current-directory (*load-truename*) + (load "../../build")) + +(ql:quickload :cl-site-woo) + +;; +;; Start aserve, publish site directory & pages, set default package. +;; +(cl-site-woo:start-server) +(cl-site-woo:publish-cl-site) +(setq *package* (find-package :cl-site)) + +(format t " + +This message from cl-site/servers/woo/serve.lisp should report the url & port +that the user may visit to browse the site. + +") + diff --git a/servers/zaserve/cl-site-zaserve.asd b/servers/zaserve/cl-site-zaserve.asd new file mode 100644 index 0000000..463d686 --- /dev/null +++ b/servers/zaserve/cl-site-zaserve.asd @@ -0,0 +1,15 @@ +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- +(in-package :cl-user) + +(asdf:defsystem cl-site-zaserve + :name "cl-site-zaserve" + :version "0.0.1" + :maintainer "Common-Lisp.Net maintainers" + :author "Dave Cooper & Common-Lisp.Net maintainers" + :licence "TBD" + :description "Test server for common-lisp.net for :zaserve AllegroServe port" + :depends-on (:cl-site :aserve) ;; FLAG -- change to :zaserve when available in QL. + :serial t + :components ((:file "package") + (:file "publish"))) + diff --git a/servers/zaserve/package.lisp b/servers/zaserve/package.lisp new file mode 100644 index 0000000..9fa4aaa --- /dev/null +++ b/servers/zaserve/package.lisp @@ -0,0 +1,4 @@ +(in-package :cl-user) + +(defpackage #:cl-site-zaserve + (:use :cl) (:export #:start-server #:publish-cl-site)) diff --git a/servers/zaserve/publish.lisp b/servers/zaserve/publish.lisp new file mode 100644 index 0000000..4a3dfd4 --- /dev/null +++ b/servers/zaserve/publish.lisp @@ -0,0 +1,83 @@ +(in-package :cl-site-zaserve) + +(defparameter *listeners* 5) + +(defun publish-cl-site (&key (output-dir cl-site:*OUTPUT-DIR*)) + (dolist (file (directory (make-pathname :defaults output-dir :name :wild :type "html"))) + (dolist (format-string (list "/~a" "/~a.htm" "/~a.html")) + (net.aserve:publish-file :path (format nil format-string (pathname-name file)) + :file (namestring file)))) + + (net.aserve:publish-directory :prefix "/" + :destination (namestring output-dir))) + + +;; +;; FLAG -- below utility functions borrowed from Gendl Remove when/if +;; Gendl is included in cl-site. On the other hand, these are a bit +;; of a mess and any feedback is welcome, to clean them up before +;; blindly :use'ing them as-is from Gendl. +;; + +(defun client-test (port) + "Check if a port is busy" ;; FLAG there must be a better way to check for + ;; a busy port than this... + #-ccl + (multiple-value-bind (result error) + (ignore-errors + (bt:with-timeout (2) + (net.aserve.client:do-http-request (format nil "http://127.0.0.1:~a" port)))) + (declare (ignore result)) + (when (typep error 'error) + port)) + ;; + ;; CCL has socket problems after calling do-http-request within an + ;; ignore-errors, when it throws an error. So we do something + ;; different. But this different thing apparently doesn't work so + ;; reliably on non-CCL. + ;; + #+ccl + (let* ((result + (handler-case + (let ((sock (usocket:socket-listen "127.0.0.1" port))) + (usocket:socket-close sock)) + (usocket:address-in-use-error (e) (declare (ignore e)) :in-use) + (t (e) (declare (ignore e)) :unknown)))) + (unless (or (member result '(:in-use :unknown)) + #+windows-host + (ignore-errors + (net.aserve.client:do-http-request + (format nil "http://127.0.0.1:~a" port)))) port))) + + + +(defun start-server (&key (port cl-site:*paserve-port*) ;; FLAG -- change to cl-site:*zaserve-port* when switched to zaserve. + (listeners *listeners*) + ;; + ;; FLAG -- figure out correct external-format for the other Lisps. + ;; + (external-format #+allegro :utf8-base #-allegro :utf8) aserve-start-args) + (net.aserve:shutdown) + (let ((wait-time 1)) + (block :outer + (do () (nil) + (let ((port port)) + (block :inner + (do ((port-free? (client-test port) (client-test port))) + (port-free? + (format t (if (> wait-time 1) "~&Retrying aserve on ~a...~%" + "~&Trying to start aserve on ~a...~%") port) + (if (ignore-errors + (apply #'net.aserve:start + :port port :listeners listeners + :external-format external-format + aserve-start-args)) + (return-from :outer port) + (progn (sleep (random wait-time)) (return-from :inner)))) + (incf port)))) + (incf wait-time 0.1))))) + + + + + diff --git a/servers/zaserve/serve.lisp b/servers/zaserve/serve.lisp new file mode 100644 index 0000000..672b155 --- /dev/null +++ b/servers/zaserve/serve.lisp @@ -0,0 +1,20 @@ +(in-package :cl-user) + +(uiop:with-current-directory (*load-truename*) + (load "../../build")) + +(ql:quickload :cl-site-zaserve) + +;; +;; Start zaserve, publish site directory & pages, set default package. +;; +(cl-site-zaserve:start-server) +(cl-site-zaserve:publish-cl-site) +(setq *package* (find-package :cl-site)) + +(let ((wserver net.aserve:*wserver*)) + (when wserver + (let ;; ((port (usocket:get-local-port (net.aserve:wserver-socket wserver)))) ;; Uncomment when switching to zaserve + ((port (acl-compat.socket::port(net.aserve:wserver-socket wserver)))) + (format t "You may now visit http://localhost:~a to test the site with zaserve.~%" port)))) + -- GitLab From 4413bedd3900c06037c40e7b12ce026afca57d6c Mon Sep 17 00:00:00 2001 From: Dave Cooper Date: Sat, 20 Oct 2018 13:33:07 -0400 Subject: [PATCH 2/4] Added default toplevel test-serve.lisp. Touched up README.md. --- Makefile | 3 ++- README.md | 32 ++++++++++++++++++++++---------- servers/README.md | 12 ++++++------ test-serve.lisp | 8 ++++++++ 4 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 test-serve.lisp diff --git a/Makefile b/Makefile index 2aa84fc..f0c4b76 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ clean: rm -rf output mkdir output -serve: paserve # May be swapped to others from time to time. +serve: static + sbcl --load test-serve.lisp paserve: static sbcl --load servers/paserve/serve.lisp diff --git a/README.md b/README.md index 7cf5f1a..b1712bb 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,7 @@ ## Directory structure -The source code for the site generator is located in the -root of the repository. The `t/` directory contains tests -for the site generator. +### Content The site content is divided over the directories `content/` and `layout`. @@ -36,6 +34,21 @@ If a file by the same name is stored in both `layout/static/` and `content/static/`, then the one in `layout/static/` takes precedence. + +### Generator Source Code + +The source code for the site generator is located in the +root of the repository. The `t/` directory contains tests +for the site generator. + +### Server Setup Code (optional) + +The `servers/` directory contains code for running various CL HTTP +servers to be able to serve the generated content locally (e.g. while +authoring/editing). It has [its own +README](https://gitlab.common-lisp.net/dcooper/cl-site/blob/master/servers/README.md). + + ## Dependencies * CL-MUSTACHE for HTML templating @@ -57,7 +70,7 @@ The Makefile contains various useful commands. Among them: * `make` - to generate the site. -* `make serve` - to generate the site and start up a test server. +* `make serve` - to generate the site and start up a default test server. * `make clean` - to remove the generated files from output directory @@ -76,13 +89,12 @@ Among them: (load ".../cl-site/test-serve.lisp") ;; replace with your actual path to cl-site/ - This will start serving the site on port 8008 (or subsequent port - numbers, if 8008 is busy). + This will start serving the site. The toplevel URL should be printed to the console. ### Known Problems - The test server crashes on load with `invalid number of arguments` on - certain 1.3.1 releases of SBCL (apparently a problem with the - `ironclad` library from quicklisp with this sbcl version). If you get - this error, try upgrading your SBCL or use CCL. + At least one of the test servers crashes on load with `invalid number + of arguments` on certain 1.3.1 releases of SBCL (apparently a problem + with the `ironclad` library from quicklisp with this sbcl + version). If you get this error, try upgrading your SBCL or use CCL. diff --git a/servers/README.md b/servers/README.md index e055288..0ff1914 100644 --- a/servers/README.md +++ b/servers/README.md @@ -45,7 +45,7 @@ and it's not listed here, please feel free to add it. Use `make` followed by the desired server name. Currently existing make targets are (note that many of these are still placeholders): - make serve # starts a default server which is expected to work. + make serve # starts a default server (from list below) which is expected to work. make clack # Aims to provide a server-agnostic veneer on top of any actual webserver. make cl-http # The world's first HTTP1.1 server; powered whitehouse.gov under President Clinton. make htoot # Hunchentoot (the "800lb Gorilla" of CL webservers). @@ -59,9 +59,9 @@ make targets are (note that many of these are still placeholders): Load the following files to get the corresponding servers running from within Lisp (note: if you try to do more than one at a time, your mileage may vary. It'd be interesting though. Who can get them all -running at the same time (on distinct ports, of course, as defined -below) (substitute the path to your `cl-site/` direcotry for the -`...`): +running at the same time in the same running CL session? (on distinct +ports, of course, as defined below) (substitute the path to your +`cl-site/` direcotry for the `...`): (load ".../cl-site/servers/clack/serve") (load ".../cl-site/servers/cl-http/serve") @@ -98,8 +98,8 @@ Each subdirectory should contain the following: user how to visit the locally served site in their browser. -Finally, for each server there should be a corresponding distinct -default starting port number defined as a global parameter in +Also, for each server there should be a corresponding distinct default +starting port number defined as a global parameter in `cl-site/globals.lisp` with its symbol exported in `cl-site/package.lisp` -- see existing one(s) for the expected nomenclature. diff --git a/test-serve.lisp b/test-serve.lisp new file mode 100644 index 0000000..2898504 --- /dev/null +++ b/test-serve.lisp @@ -0,0 +1,8 @@ +(in-package :cl-user) + +(uiop:with-current-directory (*load-truename*) + ;; + ;; May be swapped with others in servers/ from time to time. + ;; + (load "servers/paserve/serve")) + -- GitLab From 47638194e51007271d49707d576e692edde16479 Mon Sep 17 00:00:00 2001 From: Dave Cooper Date: Sat, 20 Oct 2018 13:37:22 -0400 Subject: [PATCH 3/4] Touched up README. --- servers/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/servers/README.md b/servers/README.md index 0ff1914..19ed9f1 100644 --- a/servers/README.md +++ b/servers/README.md @@ -26,8 +26,8 @@ your local host. Note that the Common-Lisp.Net maintainers cannot commit to maintaining all these webservers in guaranteed working order at all times. It is -expected that individual volunteers will be responsible for each -server (i.e. each subdirectory). +hoped that individual volunteers may step up and take responsibity for +each server (i.e. each subdirectory). Some of these subdirectories contain only stubs (i.e. placeholders) at present, and if it represents a server you are interested in, please -- GitLab From c3e6c5ff7549a2b02a01bab5eca76299e9dcfeb1 Mon Sep 17 00:00:00 2001 From: Dave Cooper Date: Sat, 20 Oct 2018 14:10:30 -0400 Subject: [PATCH 4/4] Touched up servers/README.md. --- servers/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/servers/README.md b/servers/README.md index 19ed9f1..30db1d8 100644 --- a/servers/README.md +++ b/servers/README.md @@ -8,7 +8,11 @@ frameworks continue to evolve rapidly today. There is a somewhat outdated list of CL webservers [here](https://www.cliki.net/HTTP%20server). Consider volunteering to -help bring this list up to date. +help bring this list up to +date. [These](https://github.com/CodyReichert/awesome-cl) +[awesome](https://github.com/azzamsa/awesome-cl-software) +[lists](https://github.com/vindarel/curated-awesome-cl) also appear +active these days. ## Purpose @@ -60,7 +64,7 @@ Load the following files to get the corresponding servers running from within Lisp (note: if you try to do more than one at a time, your mileage may vary. It'd be interesting though. Who can get them all running at the same time in the same running CL session? (on distinct -ports, of course, as defined below) (substitute the path to your +ports, of course, as defined below)) (substitute the path to your `cl-site/` direcotry for the `...`): (load ".../cl-site/servers/clack/serve") -- GitLab