From c5699ecfa713d040849e2564b7196a77583adb8a Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 7 Aug 2013 23:19:38 +0200 Subject: 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. --- config.example.hy | 5 +++++ hypo.hy | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/config.example.hy b/config.example.hy index d9e945c..b606d2f 100644 --- a/config.example.hy +++ b/config.example.hy @@ -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* "") diff --git a/hypo.hy b/hypo.hy index 1ebadbb..e27b62a 100755 --- a/hypo.hy +++ b/hypo.hy @@ -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)) -- cgit v1.2.3-54-g00ecf