Commit | Line | Data |
---|---|---|
fc2e11b5 SK |
1 | #! /usr/bin/env racket |
2 | #lang racket | |
3 | ;;; vim:ft=racket: | |
4 | ||
5 | (require (prefix-in env: web-server/servlet-env) | |
6 | (prefix-in log: web-server/dispatchers/dispatch-log) | |
7 | (prefix-in res: web-server/configuration/responders) | |
8 | (prefix-in xpr: web-server/http/xexpr)) | |
9 | ||
10 | ;; TODO SSL | |
11 | ||
12 | (module+ main | |
13 | (let* ([program (path->string (find-system-path 'run-file))] | |
14 | [log-file (string-append program ".log")] | |
15 | [listen-addr "0.0.0.0"] | |
16 | [listen-port 8000] | |
17 | [paths-to-serve '()] | |
18 | [browser? #f]) | |
19 | (command-line | |
20 | #:program program | |
21 | #:once-each | |
22 | [("-b" "--browser") | |
23 | "Launch web browser." | |
24 | (set! browser? #t)] | |
25 | [("-a" "--addr") | |
26 | ip-addr "Listen address." | |
27 | (set! listen-addr ip-addr)] | |
28 | [("-p" "--port") | |
29 | port-number "Listen port." | |
30 | (set! listen-port port-number)] | |
31 | [("-l" "--log") | |
32 | file "Log file." | |
33 | (set! log-file file)] | |
34 | #:args (path . paths) | |
35 | (set! paths-to-serve (cons path paths))) | |
36 | (define (custom-dispatcher _) | |
37 | (xpr:response/xexpr | |
38 | '(html | |
39 | (head) | |
40 | (body "if you're reading this - server configuration is wrong.")))) | |
41 | (env:serve/servlet | |
42 | custom-dispatcher | |
43 | #:listen-ip listen-addr | |
44 | #:port listen-port | |
45 | #:launch-browser? browser? | |
46 | #:extra-files-paths paths-to-serve | |
47 | #:log-file log-file | |
48 | #:log-format log:paren-format | |
49 | #:servlet-path "" | |
50 | ;#:servlet-regexp #rx"" ; <-- causes / to be routed to custom-dispatcher. | |
51 | ))) |