#lang scheme/base
(require scheme/match
(planet untyped/dispatch:2:=1/dispatch)
(planet jaymccarthy/with-bindings:1:=2/with-bindings)
web-server/servlet-env
web-server/dispatchers/dispatch
web-server/configuration/responders
"util.scm"
"settings.scm"
"web-export.ss"
"web-support.scm"
"record.scm"
"repository.scm"
"form.scm"
"validate.scm"
"closures.scm"
"session.scm"
"js.scm"
"user.scm"
"time.scm"
"page.scm"
"compute.scm"
"profiler.scm"
"log.scm"
"task-queue.scm"
"feed.ss"
"facebook.ss"
)
(provide
(all-from-out (planet untyped/dispatch:2:=1/dispatch))
(all-from-out (planet jaymccarthy/with-bindings:1:=2/with-bindings))
request-bindings
serve
define-app
load-server-settings
server-log
web-link
wrap-each-in-list
raw-str
img
xexpr-if
url+query
url->string
get-url
form
validate
field-validate
form-id
form-markup
grab-user-input
atom-feed
atom-item
rss-feed
rss-item
rec-prop
rec-has-prop?
rec-child-prop
rec-id
rec-data
rec-set-prop!
rec-set-each-prop!
rec-remove-prop!
rec-set-data!
rec-set-rec-prop!
rec-rec-prop
load-rec
record-id-stored?
load-where
load-children
load-descendants
contains-child?
rec-add-child!
add-child-and-save!
remove-child-and-save!
rec-add-list-prop-elt!
store-rec!
delete-rec!
fresh-rec-from-data
same-rec?
only-rec-of-type
if-rec-of-type
rec-type-is?
is-descendant?
find-parent
find-ancestor
find-highest-ancestor
find-incoming-record
find-incoming-records
rec?
sort-recs-by
define-cache
define-type-cache
handle-closure-in-req
body-as-url
body-as-closure-key
num-closures-in-memory
make-closure-key
add-closure!
closure-key->url
session-put-val!
session-get-val
session-id
session-get-hash
session-replace-hash!
get-session-object
session-remove-entry!
sessioned-response
make-fresh-session
remove-session
flash-create!
flash-get!
cookied-response
list-response
js-script-invoke
js-array
js-hash
js-quote
js-call
js-call-on-load
define-page
define-session-page
page
design
**
page-url
redirect-to-page
(rename-out (response-promise-to-redirect redirect-to))
js-inc
css-inc
versioned-file-reference
declare-setting
setting
setting-set!
register-form
welcome-message
login-form
register-form
register-user!
make-unloginable-user!
current-user
user-in
created-by?
created-by-xexpr
created-by-user-rec
stamp-user-on-rec!
get-user-rec
authenticated-login!
unauthenticated-login!
if-these-users
if-login
when-login
logout-user!
created-when
created-when-str
days-since
hours-since
minutes-since
A_DAY
AN_HOUR
THIRTY_DAYS
seconds->time-string
sum-recs
profile
define-profile
make-threaded-task-queue
sleep-task-thread-for-at-least
task-inspector-lock
task-inspector-num-tasks-thunk
facebook-fn
define-facebook-required-login-page
facebook-require-login
facebook-session-key
facebook-error
facebook-uid
facebook-form
facebook-complex-val
facebook-create-object
facebook-strict-error
)
(declare-setting *APP_VERSION* 1)
(declare-setting *PAGE_NOT_FOUND_FILE* "page-not-found.html")
(declare-setting *CATCH-EXCEPTION?* (lambda (exn) #t))
(declare-setting *EXCEPTION->XEXPR* (lambda (exn)
(if (exn:dispatcher? exn)
(next-dispatcher)
(begin
((error-display-handler)
(exn-message exn) exn)
"Error on page."))))
(define (serve web-app)
(populate-caches)
(server-log "Server is ready at ~A (ctrl-c to stop it)." (setting *WEB_APP_URL*))
(serve/servlet #:command-line? #t
#:launch-browser? #f
#:servlet-path "/"
#:server-root-path (build-path ".")
#:servlet-regexp #rx""
#:file-not-found-responder
(gen-file-not-found-responder (build-path
"htdocs"
(setting *PAGE_NOT_FOUND_FILE*)))
#:listen-ip (setting *LISTEN_IP*)
#:port (setting *PORT*)
(lambda (req)
(let ((catch? (setting *CATCH-EXCEPTION?*))
(err (setting *EXCEPTION->XEXPR*)))
(with-handlers ((catch? err))
(final-prep-of-response
(handle-closure-in-req req
(dispatch req web-app))))))))
(define-syntax define-app
(syntax-rules ()
((_ app-name
(page-name route-syntax)
...)
(begin (provide app-name page-name ...)
(define-site app-name ((route-syntax page-name) ...))))))
(define (load-server-settings #:envo (envo #f))
(load (string-append "settings-"
(or envo
(let ((args (current-command-line-arguments)))
(if (= (vector-length args) 0)
"localhost"
(vector-ref args 0))))
".scm")))