diff --git a/pkg/serverconfig/genconfig.go b/pkg/serverconfig/genconfig.go index e10169c79..1f13de028 100644 --- a/pkg/serverconfig/genconfig.go +++ b/pkg/serverconfig/genconfig.go @@ -560,14 +560,15 @@ func genLowLevelConfig(conf *Config) (lowLevelConf *Config, err error) { } if baseURL != "" { - obj["baseURL"] = strings.TrimSuffix(baseURL, "/") u, err := url.Parse(baseURL) if err != nil { return nil, fmt.Errorf("Error parsing baseURL %q as a URL: %v", baseURL, err) } - if u.Path != "/" { - return nil, errors.New("baseURL can't have a path, only a scheme, host, and optional port.") + if u.Path != "" && u.Path != "/" { + return nil, fmt.Errorf("baseURL can't have a path, only a scheme, host, and optional port.") } + u.Path = "" + obj["baseURL"] = u.String() } if listen != "" { obj["listen"] = listen diff --git a/pkg/serverconfig/testdata/baseurl-want.json b/pkg/serverconfig/testdata/baseurl-want.json new file mode 100644 index 000000000..62494a891 --- /dev/null +++ b/pkg/serverconfig/testdata/baseurl-want.json @@ -0,0 +1,110 @@ +{ + "listen": "localhost:3179", + "auth": "userpass:camlistore:pass3179", + "https": false, + "baseURL": "http://monkey.foo.com", + "prefixes": { + "/": { + "handler": "root", + "handlerArgs": { + "blobRoot": "/bs-and-maybe-also-index/", + "ownerName": "Alice", + "searchRoot": "/my-search/", + "statusRoot": "/status/", + "stealth": false + } + }, + + "/ui/": { + "handler": "ui", + "handlerArgs": { + "jsonSignRoot": "/sighelper/", + "cache": "/cache/", + "scaledImage": "lrucache" + } + }, + + "/setup/": { + "handler": "setup" + }, + + "/status/": { + "handler": "status" + }, + + "/share/": { + "handler": "share", + "handlerArgs": { + "blobRoot": "/bs/" + } + }, + + "/sync/": { + "handler": "sync", + "handlerArgs": { + "from": "/bs/", + "to": "/index-kv/" + } + }, + + "/sighelper/": { + "handler": "jsonsign", + "handlerArgs": { + "secretRing": "/path/to/secring", + "keyId": "26F5ABDA", + "publicKeyDest": "/bs-and-index/" + } + }, + + "/bs-and-index/": { + "handler": "storage-replica", + "handlerArgs": { + "backends": ["/bs/", "/index-kv/"] + } + }, + + "/bs-and-maybe-also-index/": { + "handler": "storage-cond", + "handlerArgs": { + "write": { + "if": "isSchema", + "then": "/bs-and-index/", + "else": "/bs/" + }, + "read": "/bs/" + } + }, + + "/bs/": { + "handler": "storage-filesystem", + "handlerArgs": { + "path": "/tmp/blobs" + } + }, + + "/cache/": { + "handler": "storage-filesystem", + "handlerArgs": { + "path": "/tmp/blobs/cache" + } + }, + + "/index-kv/": { + "handler": "storage-kvfileindexer", + "handlerArgs": { + "blobSource": "/bs/", + "file": "/path/to/indexkv.db" + } + }, + + "/my-search/": { + "handler": "search", + "handlerArgs": { + "index": "/index-kv/", + "owner": "sha1-f2b0b7da718b97ce8c31591d8ed4645c777f3ef4" + } + } + + } + +} diff --git a/pkg/serverconfig/testdata/baseurl.json b/pkg/serverconfig/testdata/baseurl.json new file mode 100644 index 000000000..2f1532d4a --- /dev/null +++ b/pkg/serverconfig/testdata/baseurl.json @@ -0,0 +1,11 @@ +{ + "listen": "localhost:3179", + "auth": "userpass:camlistore:pass3179", + "baseURL": "http://monkey.foo.com", + "blobPath": "/tmp/blobs", + "kvIndexFile": "/path/to/indexkv.db", + "identity": "26F5ABDA", + "identitySecretRing": "/path/to/secring", + "ownerName": "Alice", + "shareHandlerPath": "/share/" +}