2022-09-04 10:13:36 +00:00
|
|
|
#lang racket/base
|
2022-09-11 07:38:20 +00:00
|
|
|
(require "syntax.rkt"
|
|
|
|
(for-syntax racket/base)
|
2022-09-04 13:32:45 +00:00
|
|
|
racket/string
|
|
|
|
net/url
|
|
|
|
(prefix-in host: web-server/dispatchers/dispatch-host)
|
2022-09-04 10:13:36 +00:00
|
|
|
(prefix-in pathprocedure: web-server/dispatchers/dispatch-pathprocedure)
|
|
|
|
(prefix-in sequencer: web-server/dispatchers/dispatch-sequencer)
|
|
|
|
(prefix-in lift: web-server/dispatchers/dispatch-lift)
|
2022-09-04 13:32:45 +00:00
|
|
|
(prefix-in filter: web-server/dispatchers/dispatch-filter)
|
2022-10-02 09:44:44 +00:00
|
|
|
"config.rkt"
|
|
|
|
"url-utils.rkt")
|
2022-09-04 10:13:36 +00:00
|
|
|
|
|
|
|
(provide
|
|
|
|
; syntax to make the hashmap from names
|
2022-09-16 13:56:03 +00:00
|
|
|
dispatcher-tree
|
|
|
|
; procedure to make the tree from the hashmap
|
|
|
|
make-dispatcher-tree)
|
2022-09-04 10:13:36 +00:00
|
|
|
|
|
|
|
; make a hashmap out of the provided names and call make-dispatcher-tree with it
|
|
|
|
(define-syntax (dispatcher-tree stx)
|
|
|
|
; the arguments, which are names of dispatcher variables
|
|
|
|
(define names (cdr (syntax->list stx)))
|
|
|
|
; map each name to syntax of a '(name . ,name)
|
|
|
|
(define alist (map (λ (xe) ; xe is the syntax of a name
|
|
|
|
; return instead syntax of a cons cell
|
|
|
|
(datum->syntax stx `(cons ',xe ,xe)))
|
|
|
|
names))
|
|
|
|
; make syntax to make the hash
|
|
|
|
(define ds (datum->syntax stx `(make-hasheq (list ,@alist))))
|
|
|
|
; don't forget that I'm returning *code* - return a call to the function
|
|
|
|
(datum->syntax stx `(make-dispatcher-tree ,ds)))
|
|
|
|
|
|
|
|
(define (make-dispatcher-tree ds)
|
2022-09-04 13:32:45 +00:00
|
|
|
(host:make
|
|
|
|
(λ (host-sym)
|
|
|
|
(if/out (config-true? 'canonical_origin)
|
|
|
|
(let* ([host-header (symbol->string host-sym)]
|
|
|
|
[splitter (string-append "." (url-host (string->url (config-get 'canonical_origin))))]
|
|
|
|
[s (string-split host-header splitter #:trim? #f)])
|
|
|
|
(if/in (and (eq? 2 (length s)) (equal? "" (cadr s)))
|
|
|
|
((hash-ref ds 'subdomain-dispatcher) (car s))))
|
|
|
|
(sequencer:make
|
|
|
|
(pathprocedure:make "/" (hash-ref ds 'page-home))
|
|
|
|
(pathprocedure:make "/proxy" (hash-ref ds 'page-proxy))
|
2022-09-17 10:36:04 +00:00
|
|
|
(pathprocedure:make "/search" (hash-ref ds 'page-global-search))
|
2022-10-04 08:18:30 +00:00
|
|
|
(filter:make (pregexp (format "^/~a/wiki/Category:.+$" px-wikiname)) (lift:make (hash-ref ds 'page-category)))
|
|
|
|
(filter:make (pregexp (format "^/~a/wiki/.+$" px-wikiname)) (lift:make (hash-ref ds 'page-wiki)))
|
|
|
|
(filter:make (pregexp (format "^/~a/search$" px-wikiname)) (lift:make (hash-ref ds 'page-search)))
|
|
|
|
(filter:make (pregexp (format "^/~a(/(wiki(/)?)?)?$" px-wikiname)) (lift:make (hash-ref ds 'redirect-wiki-home)))
|
2022-09-04 13:32:45 +00:00
|
|
|
(hash-ref ds 'static-dispatcher)
|
|
|
|
(lift:make (hash-ref ds 'page-not-found)))))))
|