reblocks icon indicating copy to clipboard operation
reblocks copied to clipboard

Different route behavior when using different backends

Open C-Entropy opened this issue 4 years ago • 10 comments

Example

(ql:quickload '(:weblocks :weblocks-ui :weblocks-navigation-widget))

(defpackage todo
  (:use #:cl
        #:weblocks-ui/form
        #:weblocks/html)
  (:import-from #:weblocks/widget
                #:render
                #:update
                #:defwidget)
  (:import-from #:weblocks/actions
                #:make-js-action)
  (:import-from #:weblocks/app
		#:defapp)
  (:import-from #:weblocks-navigation-widget
                #:defroutes))

(in-package todo)

(defapp tasks
  :prefix "/")

(defwidget task ()
  ())

(defmethod render ((task task))
  (with-html (:h1 "Test")))

(defroutes test
    ("/" (make-instance 'task)))

(defmethod weblocks/session:init ((app tasks))
  (declare (ignorable app))
  (make-test))

when using :(weblocks/server:start :port 40000 :server-type :hunchentoot :interface "127.0.0.1"), you should get "Test" from 127.0.0.1:4000 But both (weblocks/server:start :port 40000 :server-type :wookie :interface "127.0.0.1") and (weblocks/server:start :port 40000 :server-type :woo :interface "127.0.0.1") give error like this:

;;woo, from repl
Callback Error: the message-complete callback failed
  The value of WEBLOCKS/ROUTES::PATH is NIL, which is not of type STRING.
;;wookie, from 127.0.0.1:4000
There was an error processing your request: The value
                                              NIL
                                            is not of type
                                              SIMPLE-STRING
                                            when binding STRING

Where am I wrong?

C-Entropy avatar Mar 04 '21 05:03 C-Entropy

Code seems OK. Previously, I've used weblocks with woo and it shouldn't fail. I'll have to check it.

Which ql dists versions do you have? What will output this command:

 (ql-dist:all-dists)

;; For me it outputs:
(#<QL-DIST:DIST bordeaux-threads github-c72eca20eca6a7f6558bfc3645e946e8>
 #<QL-DIST:DIST mgl-pax github-6c4eecc1be34466756e6096d1c5071f5>
 #<QL-DIST:DIST quickdist github-be76e126b0cb3ff3fa60d2bf129032f8>
 #<QL-DIST:DIST quicklisp 2021-02-28>
 #<QL-DIST:DIST sblint github-3e6c46caec64c1136646d904522607a9>
 #<QL-DIST:DIST slynk-named-readtables github-ab9cff202f4c659d9f26560718b776cb>
 #<QL-DIST:DIST slynk github-62eaa8112b926b328a9838e7d5b21c15>
 #<QL-DIST:DIST ultralisp 20210302211500>)

svetlyak40wt avatar Mar 04 '21 09:03 svetlyak40wt

CL-USER>  (ql-dist:all-dists)
(#<QL-DIST:DIST quicklisp 2021-02-28> #<QL-DIST:DIST ultralisp 20210302220500>)

C-Entropy avatar Mar 04 '21 09:03 C-Entropy

I have tried something like this:

(ql:quickload '(:weblocks))

(defpackage todo
  (:use #:cl)
  (:import-from #:weblocks/app
		#:defapp))

(in-package todo)

(defapp tasks
  :prefix "/")

(weblocks/server:start :port 40000 :server-type :hunchentoot :interface "127.0.0.1")

(weblocks/server:start :port 40000 :server-type :wookie :interface "127.0.0.1")

(weblocks/debug:reset-latest-session)

(weblocks/server:start :port 40000 :server-type :woo :interface "127.0.0.1")

(weblocks/debug:reset-latest-session)

and still, the same error

C-Entropy avatar Mar 04 '21 10:03 C-Entropy

BTW, a simple bug is at here . I think you may want to make the "[documentaion]" a hyperlink. I think

(:p "Read more in"
	   (:a :href quickstart-url
	       "[documentaion]."
               ))

is a choice

C-Entropy avatar Mar 04 '21 10:03 C-Entropy

It seems that path-info could be NIL when using woo, is "/favicon.ico" when wookie, only "/" when using hunchentoot. I will try to figure it out.

C-Entropy avatar Mar 04 '21 14:03 C-Entropy

For woo, it returns NIL as path-info when visit '/', so you need to treat it cautiously. You can get raw path-info viewing content of env. I think wookie may come out for the same reason, but I don't have time to test it now. I saw you use woo at ultralisp and it work.s It looks like magic some how. Maybe it is because you use this?

(defmethod weblocks/widget:render ((widget main-routes))
  (weblocks/widget:render
   (make-login-menu))

  (call-next-method))

C-Entropy avatar Mar 04 '21 15:03 C-Entropy

As for wookie, you just simply won't get "/" when visit "/" I think it is related to clack more than weblocks Okay, it seems that the Getting started have the same bug too. I will try to figure it out

C-Entropy avatar Mar 05 '21 05:03 C-Entropy

Most probably, the problem is in Lack Request: https://github.com/fukamachi/lack/blob/master/src/request.lisp#L67-L116 it fills data about HTTP requests and Weblocks uses it here: https://github.com/40ants/weblocks/blob/reblocks/src/request.lisp#L72-L79

svetlyak40wt avatar Mar 05 '21 07:03 svetlyak40wt

Yes it is possible too. But I just remove my quicklisp and do the following things:

(ql:quickload :wookie)

(defpackage :my-website
  (:use :cl :wookie :wookie-plugin-export))

(in-package :my-website)

;; setup a simple homepage
(defroute (:get "/") (req res)
  (send-response res :body "Welcome to my app!"))

;; start the event loop that Wookie runs inside of
(as:with-event-loop ()
  ;; create a listener object, and pass it to start-server, which starts Wookie
  (let* ((listener (make-instance 'listener
                                  :bind nil  ; equivalent to "0.0.0.0" aka "don't care"
                                  :port 8082))
         ;; start it!! this passes back a cl-async server class
         (server (start-server listener)))
    ;; stop server on ctrl+c
    (as:signal-handler 2
      (lambda (sig)
        (declare (ignore sig))
        ;; remove our signal handler (or the event loop will just sit indefinitely)
        (as:free-signal-handler 2)
        ;; graceful stop...rejects all new connections, but lets current requests
        ;; finish.
        (as:close-tcp-server server)))))

and the same error occur again.

For woo:

(ql:quickload :woo)
(woo:run (lambda (env)
	   (format t ">>>~A<<<" (getf env :path-info))
	    '(200 (:content-type "text/plain") ("Hello, World"))))

gives:

>>>NIL<<<>>>/favicon.ico<<<

when visiting '/'

C-Entropy avatar Mar 05 '21 09:03 C-Entropy

Alright, I found it that both woo and wookie is using quri, which return NIL when visit something like 127.0.0.1:8080. I have open an issue here, should fix them both.

C-Entropy avatar Mar 05 '21 10:03 C-Entropy