-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser-view.rkt
executable file
·30 lines (26 loc) · 1.27 KB
/
browser-view.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env racket
#lang racket/base
;; Quick and dirty program to view a local file under a web serving
;; environment.
(require web-server/servlet
web-server/servlet-env
racket/cmdline)
(define a-file (command-line #:args (filename) filename))
(define-values (base name dir?) (split-path a-file))
(serve/servlet (lambda (req)
(error 'req "shouldn't ever be here"))
#:servlet-path (string-append "/" (path->string name))
#:servlet-regexp #px"$^"
#:port (+ (add1 (random 8000)) 1024)
#:command-line? #t
#:launch-browser? #t
#:extra-files-paths (list
(cond [(eq? base #f)
(error 'serve "Don't know how to serve ~e" a-file)]
[(eq? base 'relative)
(simplify-path (current-directory))]
[(absolute-path? base)
base]
[else
(simplify-path (build-path (current-directory)
base))])))