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

Carlo Capelli <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CABty9wxECS2tjRv7Fm4DHHY3J7MC+it8c=ugcBKhhs7Gm=N6Fw@mail.gmail.com>
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
>
-------------- next part --------------
HTML attachment scrubbed and removed
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.