Add *prefix* option

`*prefix*' specifies which directory the application should run
under. This is useful when not running it on a domain or
sub-domain. This should contain a trailing `/' if used.
This commit is contained in:
Tom Willemse 2013-08-07 23:19:38 +02:00
parent ebd4666b17
commit c5699ecfa7
2 changed files with 10 additions and 5 deletions

View file

@ -17,3 +17,8 @@
(def *dbuser* "") ; User to log in with
(def *dbpw* "") ; Password to log in with
(def *dbname* "") ; Database to use
;; Prefix to use when running. This option should contain a trailing
;; `/'. An example would be: if you're running this project under
;; http://example.com/hypo/ you should use "hypo/".
(def *prefix* "")

10
hypo.hy
View file

@ -27,10 +27,10 @@
(sys.exit 1)))
(def render (web.template.render "templates/"))
(def urls (, "/raw/(.*)" "raw"
"/dl/(.*)" "download"
"/([a-f0-9]{7})$" "html"
"/(.*)" "upload"))
(def urls (, (+ "/" *prefix* "raw/(.*)") "raw"
(+ "/" *prefix* "dl/(.*)") "download"
(+ "/" *prefix* "([a-f0-9]{7})$") "html"
(+ "/" *prefix* "(.*)") "upload"))
(def db
(kwapply (web.database)
{"dbn" "postgres" "user" *dbuser* "pw" *dbpw* "db" *dbname*}))
@ -127,7 +127,7 @@
"filename" name
"type" (get-type (get (os.path.splitext name) 1))})
(setv web.ctx.status "201 Created")
(+ web.ctx.home "/" (get h 0) "\n")))]])
(+ web.ctx.home "/" *prefix* (get h 0) "\n")))]])
(when (= __name__ "__main__")
(let ((sys.argv (slice sys.argv 1))