Skip to content

Commit

Permalink
Some cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wielemaker authored and Jan Wielemaker committed Aug 24, 2014
1 parent 2475db1 commit 9e2c109
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 0 additions & 3 deletions daemon.pl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@

:- set_prolog_flag(verbose, silent).
:- use_module(library(http/http_unix_daemon)).
:- use_module(library(broadcast)).

:- use_module(server, []).
:- use_module(todo).

:- initialization http_daemon.
:- listen(http(pre_server_start), attach_todo_db).
8 changes: 7 additions & 1 deletion server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(settings)).
:- use_module(library(broadcast)).

:- use_module(todo).

:- set_setting_default(http:cors, [*]).
Expand All @@ -14,12 +16,16 @@
%
% Attach the TODO persistent store and start the web-server on
% Port.
%
% @see daemon.pl to start this file as a (Unix) service

server :-
server(3030).
server(Port) :-
attach_todo_db,
broadcast(http(pre_server_start)),
http_server(http_dispatch,
[ port(Port),
workers(16)
]).

:- listen(http(pre_server_start), attach_todo_db(data)).
9 changes: 6 additions & 3 deletions todo.pl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
:- module(todo,
[ attach_todo_db/0
[ attach_todo_db/1 % +Dir
]).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_json)).
:- use_module(library(http/http_cors)).
:- use_module(library(http/http_path)).
:- use_module(library(option)).
:- use_module(library(uuid)).
:- use_module(library(filesex)).
:- use_module(library(persistency)).

:- http_handler(root(todo), todo, [prefix]).
Expand Down Expand Up @@ -150,5 +151,7 @@
completed:boolean,
order:integer).

attach_todo_db :-
db_attach('todo.db', []).
attach_todo_db(Dir) :-
make_directory_path(Dir),
directory_file_path(Dir, 'todo.db', DB),
db_attach(DB, []).

0 comments on commit 9e2c109

Please sign in to comment.