63 lines
1.4 KiB
Prolog
63 lines
1.4 KiB
Prolog
:- use_module(library(http/html_head)).
|
|
:- use_module(library(http/html_write)).
|
|
:- use_module(library(http/http_client)).
|
|
:- use_module(library(http/http_header)).
|
|
:- use_module(library(http/http_json)).
|
|
:- use_module(library(http/http_server)).
|
|
:- use_module(library(http/http_session)).
|
|
:- use_module(library(http/js_write)).
|
|
:- use_module(library(http/json)).
|
|
:- use_module(library(http/json_convert)).
|
|
:- use_module(library(persistency)).
|
|
|
|
:- ['routes/login.pl'].
|
|
:- ['routes/products.pl'].
|
|
:- ['routes/users.pl'].
|
|
:- ['views/cart.pl'].
|
|
:- ['views/login.pl'].
|
|
:- ['views/products.pl'].
|
|
|
|
hang :-
|
|
sleep(600),
|
|
hang.
|
|
|
|
run :-
|
|
http_server([port(8080)]),
|
|
hang.
|
|
|
|
:- initialization
|
|
absolute_file_name('database.db', File, [access(write)]),
|
|
db_attach(File, []),
|
|
db_sync_all(gc(always)).
|
|
|
|
:- json_object
|
|
product(name:atom, price:integer).
|
|
:- persistent
|
|
product(name:atom, price:integer).
|
|
|
|
:- json_object
|
|
login(username:atom, password:atom).
|
|
|
|
:- json_object
|
|
user(username:atom).
|
|
:- persistent
|
|
user(username:atom, password_hash:atom).
|
|
|
|
:- json_object
|
|
token(username:atom, token:atom).
|
|
:- persistent
|
|
token(username:atom, token:atom).
|
|
|
|
:- persistent
|
|
session(session:atom, username:atom).
|
|
|
|
:- persistent
|
|
cart_entry(session:atom, items:atom).
|
|
|
|
:- json_object
|
|
error(error:atom).
|
|
|
|
reply_prolog(Term) :-
|
|
prolog_to_json(Term, Json),
|
|
reply_json(Json).
|
|
|