Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ TEMPLATES_PATH=custom-templates ./machine-admin server
TEMPLATES_PATH=custom-templates make run-server
```

Note that running `make runlive` will cause your `TEMPLATES_PATH` environment variable to be ignored, so that the templates directory at `web/templates` (relative to the root of this repository) is always used.

You can also provide multiple directories delimited by colons, for example:
```bash
TEMPLATES_PATH=~/.local/share/machine-admin/template-overrides:custom-templates ./machine-admin server
```
Then the directories will be overlaid (like in Linux overlay filesystems) from left to right, with the leftmost directory on top.

#### HTTP Server

You can override the default port (`3001`) or base path (`/`) of the HTTP server with the `HTTP_PORT` and `HTTP_BASEPATH` environment variables, respectively. For example, you could run the web server on port 3002 with base path `/admin/panel/` by running the following command:
Expand Down
3 changes: 2 additions & 1 deletion internal/app/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/openUC2/machine-admin/internal/app/server/routes"
"github.com/openUC2/machine-admin/internal/app/server/routes/assets"
"github.com/openUC2/machine-admin/internal/app/server/tmplfunc"
"github.com/openUC2/machine-admin/internal/clients/templates"
"github.com/openUC2/machine-admin/web"
)

Expand All @@ -41,7 +42,7 @@ func New(config conf.Config, logger godest.Logger) (s *Server, err error) {
}

s.Embeds = web.NewEmbeds()
templatesOverlay := &OverlayFS{
templatesOverlay := &templates.OverlayFS{
Upper: s.Globals.Base.Templates.GetFS(),
Lower: s.Embeds.TemplatesFS,
}
Expand Down
22 changes: 19 additions & 3 deletions internal/clients/templates/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,25 @@ func NewClient(c Config) *Client {
}

func (c *Client) GetFS() fs.FS {
path := c.Config.Path
if path == "" {
paths := c.Config.Paths
switch len(paths) {
case 0:
return nil
case 1:
return os.DirFS(paths[0])
}
return os.DirFS(path)

overlay := &OverlayFS{}
suboverlay := overlay
for i, path := range paths {
suboverlay.Upper = os.DirFS(path)
if i+1 == len(paths)-1 {
suboverlay.Lower = os.DirFS(paths[i+1])
break
}
nextSuboverlay := &OverlayFS{}
suboverlay.Lower = nextSuboverlay
suboverlay = nextSuboverlay
}
return overlay
}
9 changes: 7 additions & 2 deletions internal/clients/templates/conf.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package templates

import (
"strings"

"github.com/sargassum-world/godest/env"
)

const envPrefix = "TEMPLATES_"

type Config struct {
Path string
Paths []string
}

func GetConfig() (c Config, err error) {
// This is a file path specific to ImSwitch OS
const defaultPath = ""
c.Path = env.GetString(envPrefix+"PATH", defaultPath)
c.Paths = strings.Split(env.GetString(envPrefix+"PATH", defaultPath), ":")
if len(c.Paths) == 1 && c.Paths[0] == "" {
c.Paths = nil
}

return c, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package templates

const (
PathErrorOpLstat = "lstat"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package templates

import (
"iter"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package templates

import (
"cmp"
Expand Down
Loading