Git Product home page Git Product logo

Comments (6)

rla avatar rla commented on June 26, 2024

Hello!

I think you need something like this: https://gist.github.com/rla/b448a07d567bcc69650566a23b23c668.

See also docs for the http_server_hook predicate.

from alternative-router.

flashpixx avatar flashpixx commented on June 26, 2024

I try this also

:- use_module(library(http/http_unix_daemon)).
:- use_module(library(arouter)).


http_unix_daemon:http_server_hook(Options) :-
    http_server(handle_request, Options).

handle_request(Request) :-
    (   aroute(Request)
    ->  true
    ;   http_dispatch(Request)).


:- route_get( hello/Name, handle_hello(Name) ).

handle_hello(Name):-
    format('Content-Type: text/plain; charset=UTF-8~n~n'),
    format('Hello ~w', [Name]).


:- initialization(http_daemon, main).

But the error is ERROR: service `true' does not exist. IMHO the handle_request is not bind correctly. With the example within the readme http_server it works, but with http_daemon it does not , but for a service I need the daemon call

Your given example breaks with the same service error

from alternative-router.

rla avatar rla commented on June 26, 2024

Tested this:

:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_unix_daemon)).
:- use_module(library(arouter)).

:- route_get(hello/Name, handle_hello(Name)).

handle_hello(Name):-
    format('Content-Type: text/plain; charset=UTF-8~n~n'),
    format('Hello ~w', [Name]).

http_unix_daemon:http_server_hook(Options):-
    http_server(handle_request, Options).

handle_request(Request):-
    (   route(Request)
    ->  true
    ;   http_dispatch(Request)).

:- initialization(http_daemon, main).

With command: swipl -s test.pl -- --port=8000 --interactive=true.

from alternative-router.

flashpixx avatar flashpixx commented on June 26, 2024

Sorry, no it does not work, same error message, I run the script with swipl -O server.prolog --no-fork --port 8080 I need the --no-fork option for the daemon, but I tested it with -s and --interactive=true. My SWI-Prolog version is 7.6.4

from alternative-router.

rla avatar rla commented on June 26, 2024

Make sure you got the right arouter package:
pack_install('http://packs.rlaanemets.com/alternative-router/arouter-1.1.1.tgz').

There is same pack with same name but from other author and a bit modified code.

And remove all other code, the example as-is must work. arouter has no reference to any kind of services, it must be some other code.

from alternative-router.

flashpixx avatar flashpixx commented on June 26, 2024

I just reinstall the package with the URL, after that it works, thanks

from alternative-router.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.