Compare commits
6 commits
573241f7bb
...
51f9be1486
Author | SHA1 | Date | |
---|---|---|---|
51f9be1486 | |||
a5f2d430e1 | |||
773a659c3e | |||
9719eefed4 | |||
143196d737 | |||
9cf1428517 |
6 changed files with 31 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
# 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-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)
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ func serve() {
|
|||
logger.L.Infof("Initialized storage backend %q", conf.StorageType)
|
||||
dexConf := dex_server.Config{
|
||||
Web: dex_server.WebConfig{
|
||||
Dir: "./",
|
||||
Dir: conf.StaticDir,
|
||||
Theme: "default",
|
||||
},
|
||||
Storage: storageType,
|
||||
|
|
|
@ -17,10 +17,11 @@ type envVar string
|
|||
const (
|
||||
varLogLevel envVar = "LOG_LEVEL"
|
||||
|
||||
varServerMode envVar = "SERVER_MODE"
|
||||
varServerHost envVar = "SERVER_HOST"
|
||||
varServerPort envVar = "SERVER_PORT"
|
||||
varServerSocket envVar = "SERVER_SOCK_PATH"
|
||||
varServerMode envVar = "SERVER_MODE"
|
||||
varServerHost envVar = "SERVER_HOST"
|
||||
varServerPort envVar = "SERVER_PORT"
|
||||
varServerSocket envVar = "SERVER_SOCK_PATH"
|
||||
varServerStaticDir envVar = "SERVER_STATIC_DIR"
|
||||
|
||||
varIssuer envVar = "ISSUER"
|
||||
|
||||
|
@ -52,10 +53,11 @@ const (
|
|||
const (
|
||||
defaultLogLevel = logrus.InfoLevel
|
||||
|
||||
defaultServerMode = ModeNet
|
||||
defaultServerHost = "0.0.0.0"
|
||||
defaultServerPort = 5000
|
||||
defaultServerSocket = ""
|
||||
defaultServerMode = ModeNet
|
||||
defaultServerHost = "0.0.0.0"
|
||||
defaultServerPort = 5000
|
||||
defaultServerSocket = ""
|
||||
defaultServerStaticDir = "./"
|
||||
|
||||
defaultIssuer = "http://localhost:5000"
|
||||
|
||||
|
@ -112,6 +114,7 @@ type AppConfig struct {
|
|||
StorageType string
|
||||
StorageConfig *StorageConfig
|
||||
OpenConnectConfig *OpenConnectConfig
|
||||
StaticDir string
|
||||
}
|
||||
|
||||
func parseLevel(lvlStr string) logrus.Level {
|
||||
|
@ -142,6 +145,7 @@ func (ac *AppConfig) getConfFromEnv() {
|
|||
ac.Host = getStringFromEnv(varServerHost, defaultServerHost)
|
||||
ac.Port = getIntFromEnv(varServerPort, defaultServerPort)
|
||||
ac.SockPath = getStringFromEnv(varServerSocket, defaultServerSocket)
|
||||
ac.StaticDir = getStringFromEnv(varServerStaticDir, defaultServerStaticDir)
|
||||
|
||||
ac.StorageType = getStringFromEnv(varStorageType, string(defaultStorageType))
|
||||
ac.StorageConfig.Database = getStringFromEnv(varStorageDB, defaultStorageDB)
|
||||
|
|
|
@ -17,6 +17,7 @@ var defaultConfig = AppConfig{
|
|||
Port: defaultServerPort,
|
||||
SockPath: defaultServerSocket,
|
||||
StorageType: string(defaultStorageType),
|
||||
StaticDir: "./",
|
||||
StorageConfig: &StorageConfig{
|
||||
File: defaultStorageFile,
|
||||
Host: defaultStorageHost,
|
||||
|
|
|
@ -15,22 +15,31 @@ import (
|
|||
const StaticRoute = "/static/"
|
||||
|
||||
type StaticController struct {
|
||||
baseDir string
|
||||
}
|
||||
|
||||
func NewStaticController(baseDir string) *StaticController {
|
||||
return &StaticController{
|
||||
baseDir: baseDir,
|
||||
}
|
||||
}
|
||||
|
||||
func (sc *StaticController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
fs := http.FileServer(http.Dir("./static"))
|
||||
fs := http.FileServer(http.Dir(sc.baseDir + "/static"))
|
||||
http.StripPrefix(StaticRoute, fs).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
type IndexController struct {
|
||||
l *logrus.Logger
|
||||
downstreamConstroller http.Handler
|
||||
baseDir string
|
||||
}
|
||||
|
||||
func NewIndexController(l *logrus.Logger, downstream http.Handler) *IndexController {
|
||||
func NewIndexController(l *logrus.Logger, downstream http.Handler, baseDir string) *IndexController {
|
||||
return &IndexController{
|
||||
l: l,
|
||||
downstreamConstroller: downstream,
|
||||
baseDir: baseDir,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,9 +48,9 @@ func (ic IndexController) serveUI(w http.ResponseWriter, r *http.Request) (int,
|
|||
"issuer": func() string { return "toto" },
|
||||
}
|
||||
|
||||
lp := filepath.Join("templates", "index.html")
|
||||
hdrTpl := filepath.Join("templates", "header.html")
|
||||
footTpl := filepath.Join("templates", "footer.html")
|
||||
lp := filepath.Join(ic.baseDir, "templates", "index.html")
|
||||
hdrTpl := filepath.Join(ic.baseDir, "templates", "header.html")
|
||||
footTpl := filepath.Join(ic.baseDir, "templates", "footer.html")
|
||||
tmpl, err := template.New("index.html").Funcs(funcs).ParseFiles(hdrTpl, footTpl, lp)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, -1, fmt.Errorf("failed to init template: %w", err)
|
||||
|
|
|
@ -64,8 +64,8 @@ func New(appConf *config.AppConfig, dexSrv *dex_server.Server, logger *logrus.Lo
|
|||
}
|
||||
|
||||
controllers := map[string]http.Handler{
|
||||
ui.StaticRoute: middlewares.WithLogger(&ui.StaticController{}, logger),
|
||||
"/": middlewares.WithLogger(ui.NewIndexController(logger, dexSrv), logger),
|
||||
ui.StaticRoute: middlewares.WithLogger(ui.NewStaticController(appConf.StaticDir), logger),
|
||||
"/": middlewares.WithLogger(ui.NewIndexController(logger, dexSrv, appConf.StaticDir), logger),
|
||||
}
|
||||
|
||||
m := http.NewServeMux()
|
||||
|
|
Loading…
Reference in a new issue