Re: serving css/js out of subdirectories w/ http_reply_from_files
Wouter Beek <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAE1un7OTVSau-zO_B-mTkuM3YFfJOcME2urNL19rm4gcf7uM=w@mail.gmail.com> |
Hi,
Maybe this is superfluous, but when I was using this for the first
time I did not immediately get that in statement [1] the former
occurrence of `css` refers to the HTTP location (registered with
http:location/3), whereas the latter occurrence of `css` refers to the
file system path with alias `css` (registered with
user:file_search_path/2).
~~~{.pl}
[1] :- http_handler(css(.), serve_files_in_directory(css), [prefix]).
~~~
---
Cheers!,
Wouter.
E-mail: [email protected]
WWW: www.wouterbeek.com
Tel.: 0647674624
On Tue, Jan 21, 2014 at 4:51 PM, Daniel Lyons <[email protected]> wrote:
> Carlo,
>
> Thanks for this! It will be very helpful to me!
>
> I have also been going through Anne's tutorial, which is very helpful,
> but I don't recall seeing anything about use:file_search_path, so this
> is great stuff.
>
> Thanks again,
>
> Carlo Capelli writes:
>
>> Hi Daniel
>>
>>
>> Some time ago I had the same puzzle to solve, crafting a server with
>> bootstrap <http://getbootstrap.com/> front end. I ended up with this
>> structure
>>
>> ...
>>
>> user:file_search_path(css, document_root(css)).
>>
>> user:file_search_path(js, document_root(js)).
>>
>>
>> ...
>>
>> :- http_handler(css(.), serve_files_in_directory(css), [prefix]).
>>
>> :- http_handler(js(.), serve_files_in_directory(js), [prefix]).
>>
>>
>> start :-
>>
>> ( debugging(serv) -> set_prolog_flag(verbose_file_search, true) ; true ),
>>
>> setup_doc_tree,
>>
>> port(P),
>>
>> http_server(http_dispatch, [port(P)]),
>>
>> clear_svg_dir,
>>
>> fat('http://localhost:~d', [P], U), % it's format(atom(U)... )
>>
>> www_open_url(U).
>>
>>
>> setup_doc_tree :-
>>
>> ( \+ user:file_search_path(document_root, _Curr)
>>
>> -> working_directory(Pwd, Pwd),
>>
>> asserta(user:file_search_path(document_root, Pwd)),
>>
>> debug(serv, 'document_root now (~w)~n', [Pwd])
>>
>> ; true % debug(serv, 'document_root was (~w)~n', [Curr])
>>
>> ).
>>
>>
>> HTH Carlo
>>
>>
>> 2014/1/21 Daniel Lyons <[email protected]>
>>
>>> Hi,
>>>
>>> My apologies for such a basic question, but for some reason I'm having
>>> trouble wrapping my head around the notations. I have CSS and JavaScript
>>> files in css and js off the project directory. I want to serve them. I feel
>>> like this should work:
>>>
>>> :- http_handler(css(.), http_reply_from_files(css, []), [prefix]).
>>> :- http_handler(js(.), http_reply_from_files(js, []), [prefix]).
>>>
>>> Yet, when I run this I get no browsing on /css or /js, and when I try to
>>> hit files that definitely exist, I get (for instance) source_sink
>>> `css(bootstrap.css)' does not exist. The containing folder fails with:
>>>
>>> goal unexpectedly failed:
>>> http_server_files:serve_files_in_directory(css,[protocol(http),peer(ip(127,0,0,1)),pool(client(httpd@8001,user:http_dispatch,<stream>(0x7fdc39d330f0),<stream>(0x7fdc39d33690))),input(<stream>(0x7fdc39d330f0)),method(get),request_uri(/css/),path(/css/),http_version(1-1),host(localhost),port(8001),accept([media(text/html,[],1.0,[]),media(application/xhtml+xml,[],1.0,[]),media(application/xml,[],0.9,[]),media(_G2560/_G2561,[],0.8,[])]),accept_language(en-us),connection(keep-alive),accept_encoding(gzip,
>>> deflate),user_agent(Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1)
>>> AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11)])
>>>
>>> Any advice? I'm sure I'm doing something stupid.
>>>
>>> Thanks,
>>>
>>> —
>>> Daniel Lyons
>>>
>>>
>>>
>>> _______________________________________________
>>> SWI-Prolog mailing list
>>> [email protected]
>>> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>>>
>
>
> --
> Daniel Lyons
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>