Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different route behavior when using different backends #3

Open
C-Entropy opened this issue Mar 4, 2021 · 10 comments
Open

Different route behavior when using different backends #3

C-Entropy opened this issue Mar 4, 2021 · 10 comments

Comments

@C-Entropy
Copy link

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?

@svetlyak40wt
Copy link
Member

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>)

@C-Entropy
Copy link
Author

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

@C-Entropy
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

@svetlyak40wt
Copy link
Member

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

@C-Entropy
Copy link
Author

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
Copy link
Author

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.

@svetlyak40wt svetlyak40wt transferred this issue from 40ants/weblocks Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants