aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-08-07 23:19:38 +0200
committerGravatar Tom Willemse2013-08-07 23:23:30 +0200
commitc5699ecfa713d040849e2564b7196a77583adb8a (patch)
tree935201fd017573202ffd9be804410b0be462f57d
parentebd4666b1737e33f43f34cbdcd49bc645a556bd3 (diff)
downloadhypo-c5699ecfa713d040849e2564b7196a77583adb8a.tar.gz
hypo-c5699ecfa713d040849e2564b7196a77583adb8a.zip
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.
-rw-r--r--config.example.hy5
-rwxr-xr-xhypo.hy10
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))