Artifact Content

Not logged in

Artifact 87378b1a42e24b2ab40f9c554a19df2e0f5531ed:


%%%
%%% server.pl
%%% Prototype server
%%%

:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_server_files)).
:- use_module(library(pengines)).

% Load the other components.
:- use_module('plsrc/checker').
:- use_module('plsrc/program').



% Add search paths for ./res and ./lib
% TODO: Figure out the correct way to do this (reference the current WD).
user:file_search_path(res,ResPath) :-
    absolute_file_name('.',WD),
    atom_concat(WD,'/res',ResPath).
user:file_search_path(lib,ResPath) :-
    absolute_file_name('.',WD),
    atom_concat(WD,'/lib',ResPath).
user:file_search_path(src,ResPath) :-
    % Is this necessary?
    absolute_file_name('.',WD),
    atom_concat(WD,'/src',ResPath).

user:file_search_path(examples,ResPath) :-
    absolute_file_name('.',WD),
    atom_concat(WD,'/examples',ResPath).

% This makes ./plsrc available so we can do things like
% use_module(plsrc(program)).
user:file_search_path(plsrc,ResPath) :-
    absolute_file_name('.',WD),
    atom_concat(WD,'/plsrc',ResPath).

% Install PEngine applications (repl, passist)
:- pengine_application(repl).
:- use_module(repl:'./apps/repl/repl').

:- pengine_application(passist).
:- use_module(passist:'./apps/passist/passist').

% This makes it so that all users are authenticated, and all authenticated users
% can run non-sandboxed code. 
pengines:not_sandboxed(_,_).
pengines:authentication_hook(_,_,user).

:- http_handler(root(src), serve_files_in_directory(src), [prefix]).
:- http_handler(root(res), serve_files_in_directory(res), [prefix]).
:- http_handler(root(lib), serve_files_in_directory(lib), [prefix]).
:- http_handler(root(examples), serve_files_in_directory(examples), [prefix]).

% Simple index handler, so that I don't have to stare at a 404 on startup.
%:- http_handler('/index.html', show_index, []).


% server(), server(Port)
% Start the Arend server on the specified port (defaults to 4001).
start :- server(4001).
server(Port) :-
      http_server(http_dispatch, [port(Port)]).


% Provide a gentle way to stop the server. (Can be used to restart.)
stop :- http_stop_server(4001, []).


% Start the server on load.
:- initialization(start).