1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

api: add COMMENTO_STATIC environment variable

Closes https://gitlab.com/commento/commento-ce/issues/2
This commit is contained in:
Adhityaa
2018-06-09 13:57:47 +05:30
parent 88165504f3
commit 432ffeebb3
6 changed files with 103 additions and 14 deletions

View File

@ -2,9 +2,17 @@ package main
import (
"os"
"strings"
"path/filepath"
)
func parseConfig() error {
binPath, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
logger.Fatalf("cannot load binary path: %v", err)
return err
}
defaults := map[string]string{
"POSTGRES": "postgres://postgres:postgres@localhost/commento?sslmode=disable",
@ -13,6 +21,8 @@ func parseConfig() error {
"CDN_PREFIX": "",
"STATIC": binPath,
"SMTP_USERNAME": "",
"SMTP_PASSWORD": "",
"SMTP_HOST": "",
@ -42,5 +52,23 @@ func parseConfig() error {
os.Setenv("CDN_PREFIX", os.Getenv("ORIGIN"))
}
static := os.Getenv("STATIC")
for strings.HasSuffix(static, "/") {
static = static[0:len(static)-1]
}
file, err := os.Stat(static)
if err != nil {
logger.Errorf("cannot load %s: %v", static, err)
return err
}
if !file.IsDir() {
logger.Errorf("COMMENTO_STATIC=%s is not a directory", static)
return errorNotADirectory
}
os.Setenv("STATIC", static)
return nil
}