racketmq-2017/racketmq/hub/static-content.rkt

27 lines
971 B
Racket

#lang syndicate/actor
(require racket/file)
(require racket/runtime-path)
(require web-server/dispatchers/filesystem-map)
(require web-server/private/mime-types)
(require/activate syndicate/drivers/web)
(require "../private/util.rkt")
(require "../protocol.rkt")
(begin-for-declarations
(define-runtime-path htdocs-path "../htdocs")
(define path->mime-type (make-path->mime-type "/etc/mime.types")))
(actor #:name 'static-content-server
(define url->path (make-url->path htdocs-path))
(during (local-host $host-name $port)
(on (web-request-get (id req) (vh host-name port) ,_)
(define-values (path path-pieces)
(url->path (resource->url (web-request-header-resource req))))
(when (file-exists? path)
(web-respond/bytes! id
#:header (web-response-header #:mime-type (path->mime-type path))
(file->bytes path))))))