2016-11-30 05:08:35 +00:00
|
|
|
#lang syndicate/actor
|
|
|
|
|
|
|
|
(require racket/file)
|
|
|
|
(require racket/runtime-path)
|
|
|
|
(require net/url)
|
|
|
|
(require web-server/dispatchers/filesystem-map)
|
|
|
|
(require web-server/private/mime-types)
|
|
|
|
|
|
|
|
(require "protocol.rkt")
|
|
|
|
|
|
|
|
(require/activate syndicate/reload)
|
|
|
|
(require/activate syndicate/drivers/filesystem)
|
|
|
|
(require/activate syndicate/drivers/web)
|
|
|
|
|
|
|
|
(begin-for-declarations
|
|
|
|
(define-runtime-path htdocs-path "../htdocs")
|
|
|
|
(define-runtime-path templates-path "../htdocs/templates")
|
2017-03-09 22:30:39 +00:00
|
|
|
(define-runtime-path syndicate-js-dist-path "../../../js/dist")
|
2016-11-30 05:08:35 +00:00
|
|
|
(define path->mime-type (make-path->mime-type "/etc/mime.types")))
|
|
|
|
|
2017-02-20 17:54:52 +00:00
|
|
|
(spawn #:name 'static-content-server
|
2016-11-30 05:08:35 +00:00
|
|
|
(stop-when-reloaded)
|
2017-03-09 22:30:39 +00:00
|
|
|
(define static-paths (list htdocs-path syndicate-js-dist-path))
|
|
|
|
(define url->path-fns (map make-url->path static-paths))
|
|
|
|
(define (url->existing-static-path u)
|
|
|
|
(for/or [(url->path (in-list url->path-fns))]
|
|
|
|
(define-values (path path-pieces) (url->path u))
|
|
|
|
(and (file-exists? path) path)))
|
2016-11-30 05:08:35 +00:00
|
|
|
(on (web-request-get (id req) _ ,_)
|
2017-03-09 22:30:39 +00:00
|
|
|
(define path (url->existing-static-path
|
|
|
|
(resource->url (web-request-header-resource req))))
|
|
|
|
(when path
|
2016-11-30 05:08:35 +00:00
|
|
|
(web-respond/bytes! id
|
|
|
|
#:header (web-response-header #:mime-type (path->mime-type path))
|
|
|
|
(file->bytes path)))))
|
|
|
|
|
2017-02-20 17:54:52 +00:00
|
|
|
(spawn #:name 'template-server
|
2016-11-30 05:08:35 +00:00
|
|
|
(stop-when-reloaded)
|
|
|
|
(define url->path (make-url->path templates-path))
|
|
|
|
(during (api _ (observe (ui-template $name _)))
|
|
|
|
(define-values (path path-pieces) (url->path (string->url name)))
|
2016-12-06 02:04:41 +00:00
|
|
|
(on-start (log-info "Start observation of ~v" path))
|
|
|
|
(on-stop (log-info "Stop observation of ~v" path))
|
2016-11-30 05:08:35 +00:00
|
|
|
(during (file-content path file->string $data)
|
|
|
|
(assert (api _ (ui-template name data))))))
|