Compare commits

..

3 commits

6 changed files with 16 additions and 31 deletions

View file

@ -1,7 +1,6 @@
# PolyculeConnect # PolyculeConnect
[![status-badge](https://ci-polycule-connect.chapoline.me/api/badges/1/status.svg)](https://ci-polycule-connect.chapoline.me/repos/1) [![status-badge](https://ci-polycule-connect.chapoline.me/api/badges/1/status.svg)](https://ci-polycule-connect.chapoline.me/repos/1)
[![status-badge](https://ci-server.internal.faercol.me/api/badges/2/status.svg)](https://ci-server.internal.faercol.me/repos/2)
![Project logo](./polyculeconnect/static/img/logo-text.png) ![Project logo](./polyculeconnect/static/img/logo-text.png)

View file

@ -43,7 +43,7 @@ func serve() {
logger.L.Infof("Initialized storage backend %q", conf.StorageType) logger.L.Infof("Initialized storage backend %q", conf.StorageType)
dexConf := dex_server.Config{ dexConf := dex_server.Config{
Web: dex_server.WebConfig{ Web: dex_server.WebConfig{
Dir: conf.StaticDir, Dir: "./",
Theme: "default", Theme: "default",
}, },
Storage: storageType, Storage: storageType,

View file

@ -21,7 +21,6 @@ const (
varServerHost envVar = "SERVER_HOST" varServerHost envVar = "SERVER_HOST"
varServerPort envVar = "SERVER_PORT" varServerPort envVar = "SERVER_PORT"
varServerSocket envVar = "SERVER_SOCK_PATH" varServerSocket envVar = "SERVER_SOCK_PATH"
varServerStaticDir envVar = "SERVER_STATIC_DIR"
varIssuer envVar = "ISSUER" varIssuer envVar = "ISSUER"
@ -57,7 +56,6 @@ const (
defaultServerHost = "0.0.0.0" defaultServerHost = "0.0.0.0"
defaultServerPort = 5000 defaultServerPort = 5000
defaultServerSocket = "" defaultServerSocket = ""
defaultServerStaticDir = "./"
defaultIssuer = "http://localhost:5000" defaultIssuer = "http://localhost:5000"
@ -114,7 +112,6 @@ type AppConfig struct {
StorageType string StorageType string
StorageConfig *StorageConfig StorageConfig *StorageConfig
OpenConnectConfig *OpenConnectConfig OpenConnectConfig *OpenConnectConfig
StaticDir string
} }
func parseLevel(lvlStr string) logrus.Level { func parseLevel(lvlStr string) logrus.Level {
@ -145,7 +142,6 @@ func (ac *AppConfig) getConfFromEnv() {
ac.Host = getStringFromEnv(varServerHost, defaultServerHost) ac.Host = getStringFromEnv(varServerHost, defaultServerHost)
ac.Port = getIntFromEnv(varServerPort, defaultServerPort) ac.Port = getIntFromEnv(varServerPort, defaultServerPort)
ac.SockPath = getStringFromEnv(varServerSocket, defaultServerSocket) ac.SockPath = getStringFromEnv(varServerSocket, defaultServerSocket)
ac.StaticDir = getStringFromEnv(varServerStaticDir, defaultServerStaticDir)
ac.StorageType = getStringFromEnv(varStorageType, string(defaultStorageType)) ac.StorageType = getStringFromEnv(varStorageType, string(defaultStorageType))
ac.StorageConfig.Database = getStringFromEnv(varStorageDB, defaultStorageDB) ac.StorageConfig.Database = getStringFromEnv(varStorageDB, defaultStorageDB)

View file

@ -17,7 +17,6 @@ var defaultConfig = AppConfig{
Port: defaultServerPort, Port: defaultServerPort,
SockPath: defaultServerSocket, SockPath: defaultServerSocket,
StorageType: string(defaultStorageType), StorageType: string(defaultStorageType),
StaticDir: "./",
StorageConfig: &StorageConfig{ StorageConfig: &StorageConfig{
File: defaultStorageFile, File: defaultStorageFile,
Host: defaultStorageHost, Host: defaultStorageHost,

View file

@ -15,31 +15,22 @@ import (
const StaticRoute = "/static/" const StaticRoute = "/static/"
type StaticController struct { type StaticController struct {
baseDir string
}
func NewStaticController(baseDir string) *StaticController {
return &StaticController{
baseDir: baseDir,
}
} }
func (sc *StaticController) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (sc *StaticController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fs := http.FileServer(http.Dir(sc.baseDir + "/static")) fs := http.FileServer(http.Dir("./static"))
http.StripPrefix(StaticRoute, fs).ServeHTTP(w, r) http.StripPrefix(StaticRoute, fs).ServeHTTP(w, r)
} }
type IndexController struct { type IndexController struct {
l *logrus.Logger l *logrus.Logger
downstreamConstroller http.Handler downstreamConstroller http.Handler
baseDir string
} }
func NewIndexController(l *logrus.Logger, downstream http.Handler, baseDir string) *IndexController { func NewIndexController(l *logrus.Logger, downstream http.Handler) *IndexController {
return &IndexController{ return &IndexController{
l: l, l: l,
downstreamConstroller: downstream, downstreamConstroller: downstream,
baseDir: baseDir,
} }
} }
@ -48,9 +39,9 @@ func (ic IndexController) serveUI(w http.ResponseWriter, r *http.Request) (int,
"issuer": func() string { return "toto" }, "issuer": func() string { return "toto" },
} }
lp := filepath.Join(ic.baseDir, "templates", "index.html") lp := filepath.Join("templates", "index.html")
hdrTpl := filepath.Join(ic.baseDir, "templates", "header.html") hdrTpl := filepath.Join("templates", "header.html")
footTpl := filepath.Join(ic.baseDir, "templates", "footer.html") footTpl := filepath.Join("templates", "footer.html")
tmpl, err := template.New("index.html").Funcs(funcs).ParseFiles(hdrTpl, footTpl, lp) tmpl, err := template.New("index.html").Funcs(funcs).ParseFiles(hdrTpl, footTpl, lp)
if err != nil { if err != nil {
return http.StatusInternalServerError, -1, fmt.Errorf("failed to init template: %w", err) return http.StatusInternalServerError, -1, fmt.Errorf("failed to init template: %w", err)

View file

@ -64,8 +64,8 @@ func New(appConf *config.AppConfig, dexSrv *dex_server.Server, logger *logrus.Lo
} }
controllers := map[string]http.Handler{ controllers := map[string]http.Handler{
ui.StaticRoute: middlewares.WithLogger(ui.NewStaticController(appConf.StaticDir), logger), ui.StaticRoute: middlewares.WithLogger(&ui.StaticController{}, logger),
"/": middlewares.WithLogger(ui.NewIndexController(logger, dexSrv, appConf.StaticDir), logger), "/": middlewares.WithLogger(ui.NewIndexController(logger, dexSrv), logger),
} }
m := http.NewServeMux() m := http.NewServeMux()