On Tue, Sep 23, 2014 at 4:42 PM, George Neuner <gneu...@comcast.net>
wrote: > > 1) Is there any way to speed up initial [module] servlet loading? This is why I recommend that new users use serve/servlet, which is much faster because it does not use namespaces or live loading.
> 2) Debugging module servlets is a pain due to having to stop/restart > the server. Is there some clever way to force the server to unload a > particular servlet but keep running? Doing this pretty much requires not following my advice in question 1, but the default server (used by the command line tool) allows you to go to "/conf/refresh-servlets" and unload/reload all the servlet code.
The command-line tool is basically deprecated and only provided for backwards compatibility. There is a huge amount that it can't do at all and it hasn't been the primary way that we recommend using the Web server for a very long time.
> Not really knowing much about Racket's internals he naively asks: > Could a server pre-load the commonly used webserver modules and make > them available to new module servlets, or does the custodian > implementation make doing that difficult/impossible? This is the purpose of the make-servlet-namespace argument of configuration-table->web-config@ but there is no option in the configuration file for that argument. http://docs.racket-lang.org/web-server-internal/Web_Servers.html?q=servlet-namespace#%28def._web-config._%28%28lib._web-server%2Fweb-config-unit..rkt%29._configuration-table-~3eweb-config~40%29%29
> My application so far is based on stateful servlets and AJAX ... stateful > mainly because it's easier for me to understand. Currently there is > little use of continuations, but some planned functionality will use them > extensively and it certainly would help if debugging didn't always mean > starting over setting up conditions in the application. This comment/question is related to questions 4 and 5 from the FAQ: http://docs.racket-lang.org/web-server/faq.html?q=servlet-namespace#%28part._update-servlets%29
> If a Racket library is deliberately put into the servlet-namespace, does > that streamline linking? Your assumption about the purpose of this is not correct. Anything in the servlet-namespace will be shared between all servlets, and thus not loaded per-servlet.
web-server/servlet is NOT shared, nor is any net library or common racket library like racket/list. They are all totally unique per servlet. This, by the way, is part of why I don't recommend using dynamic servlets at all and suggest using serve/servlet.
Using 6.0.1
I was under the (maybe mistaken) impression that calling response/...
terminated the servlet thread. It seems though that it doesn't. I was
hoping to use response as an early exit, so that my servlets look like:
e.g.,
(define (user/exists request)
(let* [
(params (request-bindings request))
(username (exists-binding? 'username params))
(response (make-hash))
]
; validate request
(unless username
(response/json (hasheq 'success #f 'msg "missing username" ))
; get request parameters
(set! username (extract-binding/single 'username params))
:
; send a real response
(response/json response )
))
(define (response/json obj . cookies )
(response/output
(λ (op) (write-json obj op))
#:code 200
#:message #"OK"
#:seconds (current-seconds)
#:mime-type #"application/javascript"
#:headers (map cookie->header cookies)
))
I expected that unless would bail out if the test fails. However,
execution charges ahead into code that extracts post parameters and/or
cookie values and then I get a contract error that terminates the
servlet ... usually before my own error response is sent.
Is response supposed to terminate the servlet? If not, can I wrap a
let/ec around the whole servlet and do something like:
(define (user/exists request)
(let/ec fail
(let* [
(params (request-bindings request))
(username (exists-binding? 'username params))
(response (make-hash))
]
; validate request
(unless username
(response/json (hasheq 'success #f 'msg "missing username" )
(fail))
; get request parameters
(set! username (extract-binding/single 'username params))
:
; send a real response
(response/json response )
)))
or do I have to arrange that the response always is the last value produced?
Thanks,
George
Jay
--
Jay McCarthy
http://jeapostrophe.github.io
"Wherefore, be not weary in well-doing,
for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
- D&C 64:33
____________________