Shirakumo / radiance

A Common Lisp web application environment
https://shirakumo.github.io/radiance/
zlib License
311 stars 19 forks source link

Static files not being handled #51

Closed piknik closed 3 years ago

piknik commented 3 years ago

Hello,

I am beginning to use radiance and have attempted to follow the basics in getting started up. In my own code, I am unable to have radiance serve the static CSS files which exist in the same base directory as the project. I have tried to find out where I am going wrong in my own code.

However, I have then followed the instructions on the README step-by-step, creating a module (placed in ~/quicklisp/local-projects) and then using the code with cl-who and the provided CSS. At this point it is expected that radiance would serve the file provided by (uri-to-url "/static/example/example.css" :representation :external) but the following error was given instead:

There was nothing that could handle the request #<REQUEST GET #@":8080/static/example/example.css">.
   [Condition of type RADIANCE-CORE:REQUEST-NOT-FOUND]

  0: ((FLET "DISPATCHER16" :IN "/home/piknik/quicklisp/dists/shirakumo/software/radiance-2020.10.01_19-44-28-GMT/defaults.lisp"))
  1: (RADIANCE-CORE:DISPATCH #@":8080/static/example/example.css")
  2: (RADIANCE-CORE:EXECUTE-REQUEST #<unavailable argument> #<unavailable argument>)
  3: (RADIANCE-CORE:REQUEST #<unavailable argument> :REPRESENTATION #<unavailable argument> :HTTP-METHOD #<unavailable argument> :BODY-STREAM #<unavailable argument> :HEADERS #<unavailable argument> :POST ..
  4: ((:METHOD HUNCHENTOOT:ACCEPTOR-DISPATCH-REQUEST (I-HUNCHENTOOT::RADIANCE-ACCEPTOR T)) #<unused argument> #<HUNCHENTOOT:REQUEST {10060DA763}>) [fast-method]
  5: ((:METHOD HUNCHENTOOT:HANDLE-REQUEST (HUNCHENTOOT:ACCEPTOR HUNCHENTOOT:REQUEST)) #<I-HUNCHENTOOT::RADIANCE-ACCEPTOR (host 0.0.0.0, port 8080)> #<HUNCHENTOOT:REQUEST {10060DA763}>) [fast-method]
  6: ((:METHOD HUNCHENTOOT:PROCESS-REQUEST (T)) #<HUNCHENTOOT:REQUEST {10060DA763}>) [fast-method]
  7: (HUNCHENTOOT::DO-WITH-ACCEPTOR-REQUEST-COUNT-INCREMENTED #<I-HUNCHENTOOT::RADIANCE-ACCEPTOR (host 0.0.0.0, port 8080)> #<FUNCTION (LAMBDA NIL :IN HUNCHENTOOT:PROCESS-CONNECTION) {10060DA6CB}>)
  8: ((:METHOD HUNCHENTOOT:PROCESS-CONNECTION (HUNCHENTOOT:ACCEPTOR T)) #<I-HUNCHENTOOT::RADIANCE-ACCEPTOR (host 0.0.0.0, port 8080)> #<USOCKET:STREAM-USOCKET {1001891833}>) [fast-method]
  9: ((:METHOD HUNCHENTOOT:PROCESS-CONNECTION :AROUND (HUNCHENTOOT:ACCEPTOR T)) #<I-HUNCHENTOOT::RADIANCE-ACCEPTOR (host 0.0.0.0, port 8080)> #<USOCKET:STREAM-USOCKET {1001891833}>) [fast-method]
 10: ((FLET HUNCHENTOOT::PROCESS-CONNECTION% :IN HUNCHENTOOT::HANDLE-INCOMING-CONNECTION%) #<I-HUNCHENTOOT::RADIANCE-ACCEPTOR (host 0.0.0.0, port 8080)> #<USOCKET:STREAM-USOCKET {1001891833}>)
 11: ((FLET I-HUNCHENTOOT::THUNK :IN HUNCHENTOOT:START-THREAD))
 12: ((LAMBDA NIL :IN BORDEAUX-THREADS::BINDING-DEFAULT-SPECIALS))
 13: ((FLET SB-UNIX::BODY :IN SB-THREAD::RUN))
 14: ((FLET "WITHOUT-INTERRUPTS-BODY-11" :IN SB-THREAD::RUN))
 15: ((FLET SB-UNIX::BODY :IN SB-THREAD::RUN))
 16: ((FLET "WITHOUT-INTERRUPTS-BODY-4" :IN SB-THREAD::RUN))
 17: (SB-THREAD::RUN)
 18: ("foreign function: call_into_lisp")
 19: ("foreign function: funcall1")

Am I supposed to be running a local proxy web server like nginx or something? I'm missing something here. Perhaps some code changes were made in order to specify a static resource handler?

Shinmera commented 3 years ago

From your description I'm not sure your file hierarchy is correct? The css file has to be in the static/ directory within your module directory. So it should be example/static/example.css on disk.

piknik commented 3 years ago

From your description I'm not sure your file hierarchy is correct? The css file has to be in the static/ directory within your module directory. So it should be example/static/example.css on disk.

Correct, the example.css is in ~/quicklisp/local-projects/radiance-test/static/example.css.

Here is the ~/quicklisp/local-projects/radiance-test/radiance-test.lisp file I'm using with variations on the uri-to-url uri parameter:

(in-package #:rad-user)
(define-module #:radiance-test
  (:use #:cl #:radiance))
(in-package #:radiance-test)

(define-page example "/example" ()
  (cl-who:with-html-output-to-string (o)
    (cl-who:htm
     (:html
      (:head (:title "Example Page")
             (:link :rel "stylesheet" :type "text/css" 
                    :href (uri-to-url "/static/example.css" :representation :external)))
      (:body (:header (:h1 "Couldn't Be Simpler."))
             (:main (:p "Trust me on this one.")))))))

Also trying (uri-to-url "/static/example/example.css" :representation :external) with the same result.

If it helps, I am using the following mostly generated .asd file too:

(in-package #:cl-user)
(asdf:defsystem #:radiance-test
  :defsystem-depends-on (:radiance)
  :class "radiance:virtual-module"
  :components ((:file "radiance-test"))
  :depends-on (:cl-who))
piknik commented 3 years ago

Also if it helps here is the radiance environment ~/.config/radiance/default/radiance-core/radiance-core.conf.lisp. It has the welcome module removed from startup, and that's it (same issue with it on):

; meta (:version 1.0 :package "RADIANCE-CORE")
((:interfaces (:admin . "r-simple-admin") (:auth . "r-simple-auth")
  (:ban . "r-simple-ban") (:cache . "r-simple-cache")
  (:data-model . "r-simple-model") (:database . "i-lambdalite")
  (:relational-database . "i-sqlite") (:logger . "i-verbose")
  (:mail . "i-sendmail") (:profile . "r-simple-profile")
  (:rate . "r-simple-rate") (:server . "i-hunchentoot")
  (:session . "r-simple-sessions") (:user . "r-simple-users"))
 (:versions
  . [hash-table equal ("radiance-core" :|2.2.0|) ("i-verbose" :|1.0.0|)
     ("i-hunchentoot" :|1.1.0|) ("attridge-erp" :|0.0.2|) ("r-clip" :|1.0.0|)
     ("r-welcome" :|1.0.0|) ("r-simple-errors" :|1.0.0|)])
 (:domains "radiance" "localhost" "127.0.0.1" "::1")
 (:startup :r-simple-errors) (:routes) (:debugger . :if-swank-connected))
piknik commented 3 years ago

Well, I'm an idiot. Rather than use /static/example/example.css I used /static/radiance-test/example.css and it works.

Shinmera commented 3 years ago

Haha! Glad you managed to figure it out on your own. If you have problems in the future, don't hesitate to send another issue! :)