manuel-serrano / hop

Multitier JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is the /hop/ prefix required

vidjuheffex opened this issue · comments

Apologies if this is a dumb question:

I've been messing with Hop lately for fun. I have a sqlite/markdown powered blog on localhost:8080/hop/blog, if I were to launch this as a website I presume my blog would end up being at www.my-site.com/hop/blog

Is there a way to serve stuff at the index (www.my-site.com) as well as nested only one layer deep? (my-site.com/blog)?

This has been discussed before: https://sympa.inria.fr/sympa/arc/hop/2012-01/msg00002.html As this thread is over 8 years old, things might have changed.

Thanks, you inadvertently answered another question I had (if hop had it's own mailing list) I appreciate it!

Dear Julian,

Sorry for the slow answer. Hopefully Sven has been able to help.

Thanks, you inadvertently answered another question I had (if hop had it's own mailing list) I appreciate it!
In these days we prefer to use only one media and github seems to be a popular
place, so it's better to keep this conversation going on here.

Regarding your question, two answers depending on the programming language.

For JavaScript:

There is an api for doing that. You have to use the two service
"service.addURL" and "Service.allowURL". They are documented here:

http://hop.inria.fr/home/01-service.html

For Scheme:

You don't really need an API as for JavaScript because you can simply use
a filter that will intercept your requests and modify the URL
accordingly. The main constraint is that your filter has to be declared
inside the hoprc.hop file. For the sake of the example, let's consider
your situation. You have something such as:

$ cat > blog.hop <<EOF
(module blog)

(define-service (blog)
   (<HTML> "blog"))
EOF

To use it as "/blog", in addition to "/hop/blog", use the following:

$ cat >> .config/hop/hoprc.hop <<EOF
(hop-filter-add-always-first!
   (lambda (req)
      (when (isa? req http-server-request)
	 (with-access::http-server-request req (abspath path)
	    (when (string=? abspath "/blog")
	       (set! abspath "/hop/blog"))))
      req))
EOF

Filters are documented in the file:

hop/weblets/doc/api/filters.wiki

I'm currently updating the Hop official web site so this page will be soon
publicly available. Currently you have to access it via the source code or
here:

https://github.com/manuel-serrano/hop/blob/master/weblets/doc/api/filters.wiki

I hope this will help

--
Manuel

Thanks so much.