mirror of https://github.com/perkeep/perkeep.git
serverconfig: let baseURL and listen be optionally separate
This commit is contained in:
parent
42833a76e0
commit
11842fcf33
|
@ -232,7 +232,8 @@ func genLowLevelPrefixes(params *configPrefixesParams) jsonconfig.Obj {
|
|||
|
||||
func GenLowLevelConfig(conf *Config) (lowLevelConf *Config, err error) {
|
||||
var (
|
||||
baseUrl = conf.RequiredString("listen")
|
||||
baseURL = conf.OptionalString("baseURL", "")
|
||||
listen = conf.RequiredString("listen")
|
||||
auth = conf.RequiredString("auth")
|
||||
keyId = conf.RequiredString("identity")
|
||||
secretRing = conf.RequiredString("identitySecretRing")
|
||||
|
@ -266,10 +267,20 @@ func GenLowLevelConfig(conf *Config) (lowLevelConf *Config, err error) {
|
|||
obj["TLSKeyFile"] = "config/selfgen_key.pem"
|
||||
}
|
||||
}
|
||||
obj["baseURL"] = scheme + "://" + baseUrl
|
||||
if baseURL == "" {
|
||||
baseURL = scheme + "://" + listen
|
||||
}
|
||||
if strings.HasSuffix(baseURL, "/") {
|
||||
baseURL = baseURL[:len(baseURL)-1]
|
||||
}
|
||||
obj["baseURL"] = baseURL
|
||||
obj["https"] = tlsOn
|
||||
obj["auth"] = auth
|
||||
|
||||
if listen != "" {
|
||||
obj["listen"] = listen
|
||||
}
|
||||
|
||||
if dbname == "" {
|
||||
username := os.Getenv("USER")
|
||||
if username == "" {
|
||||
|
|
|
@ -124,6 +124,7 @@ func testConfig(name string, t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
baseName := strings.Replace(filepath.Base(name), ".json", "", 1)
|
||||
wantFile := strings.Replace(name, ".json", "-want.json", 1)
|
||||
wantConf, err := configParser().ReadFile(wantFile)
|
||||
if err != nil {
|
||||
|
@ -133,8 +134,8 @@ func testConfig(name string, t *testing.T) {
|
|||
prettyPrint(&got, lowLevelConf.Obj, 0)
|
||||
prettyPrint(&want, wantConf, 0)
|
||||
if got.String() != want.String() {
|
||||
tempGot := tempFile(got.Bytes())
|
||||
tempWant := tempFile(want.Bytes())
|
||||
tempGot := tempFile(baseName + "-got", got.Bytes())
|
||||
tempWant := tempFile(baseName + "-want", want.Bytes())
|
||||
defer os.Remove(tempGot.Name())
|
||||
defer os.Remove(tempWant.Name())
|
||||
diff, err := exec.Command("diff", "-u", tempWant.Name(), tempGot.Name()).Output()
|
||||
|
@ -146,8 +147,8 @@ func testConfig(name string, t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func tempFile(b []byte) *os.File {
|
||||
f, err := ioutil.TempFile("", "")
|
||||
func tempFile(prefix string, b []byte) *os.File {
|
||||
f, err := ioutil.TempFile("", prefix + "-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"listen": "localhost:3179",
|
||||
"baseURL": "http://localhost:3179",
|
||||
"auth": "userpass:camlistore:pass3179",
|
||||
"https": false,
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
{
|
||||
"baseURL": "http://foo.com",
|
||||
"listen": "1.2.3.4:80",
|
||||
"auth": "userpass:camlistore:pass3179",
|
||||
"https": false,
|
||||
"prefixes": {
|
||||
"/": {
|
||||
"handler": "root",
|
||||
"handlerArgs": {
|
||||
"stealth": false
|
||||
}
|
||||
},
|
||||
|
||||
"/ui/": {
|
||||
"handler": "ui",
|
||||
"handlerArgs": {
|
||||
"blobRoot": "/bs-and-maybe-also-index/",
|
||||
"searchRoot": "/my-search/",
|
||||
"jsonSignRoot": "/sighelper/",
|
||||
"cache": "/cache/",
|
||||
"scaledImage": "lrucache"
|
||||
}
|
||||
},
|
||||
|
||||
"/setup/": {
|
||||
"handler": "setup"
|
||||
},
|
||||
|
||||
"/sync/": {
|
||||
"handler": "sync",
|
||||
"handlerArgs": {
|
||||
"from": "/bs/",
|
||||
"to": "/index-mem/"
|
||||
}
|
||||
},
|
||||
|
||||
"/sighelper/": {
|
||||
"handler": "jsonsign",
|
||||
"handlerArgs": {
|
||||
"secretRing": "/path/to/secring",
|
||||
"keyId": "26F5ABDA",
|
||||
"publicKeyDest": "/bs-and-index/"
|
||||
}
|
||||
},
|
||||
|
||||
"/bs-and-index/": {
|
||||
"handler": "storage-replica",
|
||||
"handlerArgs": {
|
||||
"backends": ["/bs/", "/index-mem/"]
|
||||
}
|
||||
},
|
||||
|
||||
"/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-mem/": {
|
||||
"handler": "storage-memory-only-dev-indexer",
|
||||
"handlerArgs": {
|
||||
"blobSource": "/bs/"
|
||||
}
|
||||
},
|
||||
|
||||
"/my-search/": {
|
||||
"handler": "search",
|
||||
"handlerArgs": {
|
||||
"index": "/index-mem/",
|
||||
"owner": "sha1-f2b0b7da718b97ce8c31591d8ed4645c777f3ef4"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"listen": "1.2.3.4:80",
|
||||
"baseURL": "http://foo.com/",
|
||||
"auth": "userpass:camlistore:pass3179",
|
||||
"blobPath": "/tmp/blobs",
|
||||
"identity": "26F5ABDA",
|
||||
"identitySecretRing": "/path/to/secring"
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"listen": "1.2.3.4:443",
|
||||
"baseURL": "https://1.2.3.4:443",
|
||||
"auth": "userpass:camlistore:pass3179",
|
||||
"https": true,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"listen": "localhost:3179",
|
||||
"baseURL": "http://localhost:3179",
|
||||
"auth": "userpass:camlistore:pass3179",
|
||||
"https": false,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"listen": "localhost:3179",
|
||||
"baseURL": "http://localhost:3179",
|
||||
"auth": "userpass:camlistore:pass3179",
|
||||
"https": false,
|
||||
|
|
|
@ -307,9 +307,14 @@ func main() {
|
|||
baseURL := config.RequiredString("baseURL")
|
||||
listen := *webserver.Listen
|
||||
if listen == "" {
|
||||
// if command line was empty, use value in config
|
||||
listen = strings.TrimLeft(baseURL, "http://")
|
||||
listen = strings.TrimLeft(listen, "https://")
|
||||
// If command-line is empty, try the "listen" value from
|
||||
// the config file, else try to get it from the baseURL.
|
||||
listen = config.OptionalString("listen", "")
|
||||
if listen == "" {
|
||||
// if command line was empty, use value in config
|
||||
listen = strings.TrimLeft(baseURL, "http://")
|
||||
listen = strings.TrimLeft(listen, "https://")
|
||||
}
|
||||
} else {
|
||||
// else command line takes precedence
|
||||
scheme := strings.Split(baseURL, "://")[0]
|
||||
|
|
Loading…
Reference in New Issue