Re: serving css/js out of subdirectories w/ http_reply_from_files

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 01/21/2014 05:36 AM, Daniel Lyons wrote:
> 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.

There seems to be a conflict with library(http/http_server_files).  This 
looks like a bug, as the handlers defined there are defined with
low priority.

On the other hand, all you need to do is load the above library and
add a rule for file_search_path/2 to point to the additional directory:

:- use_module(library(http/http_server_files)).
:- multifile user:file_search_path/2.

user:file_search_path(css, css).

This does (deliberately) not allow for directory indexes, but should 
serve the files well.

	Cheers --- Jan

P.s.	Will check why your handlers do not overrule the library ones
	as they should, but not today.


>
> Thanks,
>
> �
> Daniel Lyons
>
>
>
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>

_______________________________________________
SWI-Prolog mailing list
[email protected]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.