Is it possible to use Prolog as an API via Apache? I want to use Vue.js in my project. I have an idea to use Apache2 + Vue.js on port 80 and http_server/2 on another port. Then do requests from JS to Prolog’s port. Although I’ve never launched the Prolog’s server.
So here are two questions:
Is that a good way to connect the framework with Prolog?
How to start the Prolog’s server in the background mode?
I run SWI on one port and point Apache2 (or NGINX) at that, in NGINX it’s proxy_pass, I’ve not used Apache but it does the same job. For Vue if it’s just a static HTML page being served, along with the compiled JavaScript, then Apache can serve it. Otherwise let Apache serve all the static files and SWI serve the HTML page that the Vue app is loaded into. Then JS sends requests still on port 80 to Apache, which sends it on to SWI-Prolog. This way you don’t need to expose the SWI-Prolog port to the world on your server. Keep as few ports exposed on a server as possible as a general rule of thumb.
Then I use systemd and create a service for the swipl app, setting the ExecStart parameter to that run script. Enable the service and start it. The thread_get_message(stop) goal keeps the SWI process running, I like to pass it in from the command-line so I don’t need it in my development code which I’ll be running with the REPL, but you can manage that in several ways.
I use a setting under Win10. The browser (JS) layer containing Vue.js and Babylon.js talking to a Logtalk app (includes a server, SWI als backend) and to a Python app (includes also a server). The browser is also a router makes it possible that Python and Logtalk can talk together. The communication is a simple JSON protocol (inspired XMPP) over Websockets. Works great.