<div dir="ltr"><div><div>Just realized I can the desired behavior by just putting the (string-arg) as the last clause:<br><br><span style="font-family:courier new,monospace">(define-values (url-based-dispatch url-generator)<br>

  (dispatch-rules<br>
   [("home") display-home]<br>   [("some-app") run-app]<br></span><span style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">   [((string-arg)) dispatch-static-html]</span>))</span><br>

<br></div>I'm still curious though whether it's possible to skip to the next clause by calling next-dispatcher within one dispatch function. The discussion at <br><a href="http://lists.racket-lang.org/users/archive/2013-September/059728.html">http://lists.racket-lang.org/users/archive/2013-September/059728.html</a><br>

</div>made me think this was possible. In that example, I thought that when "funny-fish.png" is matched and fail-to-fs throws next-dispatcher that the idea was for the program to keep trying with the rest of the clauses in the dispatch rules. <br>

<br>Tobias<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 17 December 2013 17:25, Janos Tobias Locsei <span dir="ltr"><<a href="mailto:jtlocsei@cantab.net" target="_blank">jtlocsei@cantab.net</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Jay, I tried again using serve/servelet. This is my full code:<br><br>#<span style="font-family:courier new,monospace">lang racket<br>

<br>(require web-server/dispatch ; for dispatch-rules<br>         web-server/dispatchers/dispatch ; for next-dispatcher<br>
         web-server/servlet-env ; for serve/servlet<br>         web-server/http ; for response/xexpr<br>         )<br><br>(define-values (url-based-dispatch url-generator)<br>  (dispatch-rules<br>   [((string-arg)) dispatch-static-html]<br>


   [("home") display-home]<br>   [("some-app") run-app]))<br><br>(define (dispatch-static-html request a-path-string)<br>  (display "Entered dispatch-static-html\n")<br>  ; This will eventually have code to search for static html <br>


  ; files and display them. For now, just pretend we couldn't find<br>  ; the relevant html file so we throw next-dispatcher.<br>  (next-dispatcher))<br><br>(define (display-home request)<br>  (display "Entered display-home\n")<br>


  (response/xexpr<br>   `(html <br>     (head (title "Home"))<br>     (body (h1 "Home")<br>           (p "Welcome to the home page")))))<br><br>(define (run-app request)<br>  (display "Entered run-app\n")<br>


  (response/xexpr<br>   `(html <br>     (head (title "App"))<br>     (body (h1 "App")<br>           (p "This app is actually just a static page")))))<br>   <br><br>(define (respond-unknown request)<br>


  (display "Entered respond-unknown\n")<br>  (response/xexpr <br>   `(html <br>     (head (title "Unknown Reponse"))<br>     (body (h1 "Unknown Response")<br>           (p "Sorry, I couldn't find what you're looking for")))))<br>


<br>(serve/servlet<br> url-based-dispatch ; answers requests<br> #:servlet-path "/home" ; default url<br> #:servlet-regexp #rx"" ; capture all top-level requests<br> #:file-not-found-responder respond-unknown)<br>


</span><div><span style="font-family:courier new,monospace"></span><br>What I was expecting (and wanting) was that for the URL "<a href="http://localhost:8000/home" target="_blank">http://localhost:8000/home</a>" the function <span style="font-family:courier new,monospace">dispatch-static-html</span> would be called (because it matches any URL), it would throw <span style="font-family:courier new,monospace">next-dispatcher</span>, and then <span style="font-family:courier new,monospace">display-home</span> would be called, since it's the next matching clause. <br>


<br>But in reality when <span style="font-family:courier new,monospace">dispatch-static-html</span> throws <span style="font-family:courier new,monospace">next-dispatcher</span> the program jumps straight to <span style="font-family:courier new,monospace">respond-unknown</span>, which I specified as the <span style="font-family:courier new,monospace">file-not-found-responder</span> keyword argument when I called <span style="font-family:courier new,monospace">serve/servlet</span>. <br>


<br>What am I missing? Is there a way to get the program to do what I wanted it to?<br><br>Thanks for all your time with this.<br><br>Tobias</div><div><span style="font-family:courier new,monospace"><br><br><br><br>-------------------------------<div class="im">

<br>
<br>Thanks Jay, that makes sense. I was testing it without using 
serve/servlet, using the example on 
<a href="http://docs.racket-lang.org/web-server/dispatch.html" target="_blank">http://docs.racket-lang.org/web-server/dispatch.html</a><br><br>I will try again using serve/servlet. </div></span></div></div><div class="gmail_extra">


<br><br><div class="gmail_quote"><div class="im">On 17 December 2013 14:45, Jay McCarthy <span dir="ltr"><<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>></span> wrote:<br></div><div>

<div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The first one is what I would write, except that I'd put it after the<br>
["" ...] case so it doesn't shadow it.<br>
<br>
How are you testing this code? (next-dispatcher) is supposed to throw<br>
an exception, but it will caught and used by the Web server when you<br>
are using serve/servlet, etc.<br>
<span><font color="#888888"><br>
Jay<br>
</font></span><div><div><br>
On Tue, Dec 17, 2013 at 7:11 AM, Janos Tobias Locsei<br>
<<a href="mailto:jtlocsei@cantab.net" target="_blank">jtlocsei@cantab.net</a>> wrote:<br>
> I thought I'd add a note about what my overall objective with this is, in<br>
> case there's a completely different way of achieving the same thing.<br>
><br>
> Basically what I want is to be able to serve a combination of apps and<br>
> static html pages on my domain, but I don't want ".html" as the end of the<br>
> url for the static pages. So, if someone goes to the url<br>
><br>
> <a href="http://mysite.com/lolcats" target="_blank">http://mysite.com/lolcats</a><br>
><br>
> ...then I'd like the web server will look in the directory<br>
> /htdocs/static-html/ and check whether there's a file called lolcats.html,<br>
> and serve that page if it's there.<br>
><br>
> My idea was that to achieve this I'd write a dispatch function that would<br>
> check the static-html directory for a file with the correct name, and serve<br>
> that page using the "include-template" function in web-server/templates.<br>
><br>
> But if there's an easier/better way of achieving the same thing then I'm<br>
> open to that.<br>
><br>
> Tobias<br>
><br>
><br>
><br>
<br>
<br>
<br>
</div></div><div><div>--<br>
Jay McCarthy <<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>><br>
Assistant Professor / Brigham Young University<br>
<a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>
"The glory of God is Intelligence" - D&C 93<br>
</div></div></blockquote></div></div></div><br></div>
</blockquote></div><br></div>