commit 25842bcb1893cd21092fb5f37bfca2209e3ae7e8
parent c79f191be541a29dfafc0dd0b9799641918c79f1
Author: weetat <wtenison@protonmail.com>
Date: Wed, 12 Feb 2025 21:48:51 +0000
Load templates from a separate WebDir setting
Add WebDir to the filesystem config and scan it for templates instead of
RootDir. The server info YAML is now looked up under RootDir/sys rather
than relative to the working directory.
Diffstat:
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/miki/miki.go b/src/miki/miki.go
@@ -92,15 +92,18 @@ type IResourceData interface {
func main() {
fmt.Println("MIKI")
+ /// PULL SYSTEM INFO FROM YAML ///
+
_fsBuffer := bytes.NewBufferString("filesysteminfo: *fs\n")
var _fs struct {
FileSystemInfo struct {
RootDir string
+ WebDir string
}
}
- decoder := yaml.NewDecoder(_fsBuffer, yaml.ReferenceDirs("sys"))
+ decoder := yaml.NewDecoder(_fsBuffer, yaml.ReferenceDirs(filepath.Join("sys")))
if err := decoder.Decode(&_fs); err != nil {
fmt.Println(err.Error())
return
@@ -118,13 +121,15 @@ func main() {
}
}
- decoder = yaml.NewDecoder(_siBuffer, yaml.ReferenceDirs("sys"))
+ decoder = yaml.NewDecoder(_siBuffer, yaml.ReferenceDirs(filepath.Join(_fs.FileSystemInfo.RootDir, "sys")))
if err := decoder.Decode(&_si); err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("%+v\n", _si)
+ /// CHECK FOR VALID CERT INFO ///
+
_tls_cert_path := filepath.Join(_si.ServerInfo.SslPath, _si.ServerInfo.CertFile)
if _, err := os.Stat(_tls_cert_path); err != nil {
log.Panicf("__PANIC\tmain:%s", err)
@@ -135,11 +140,13 @@ func main() {
log.Panicf("__PANIC\tmain:%s", err)
}
+ /// SET UP SERVER MUX ///
+
_mux := http.NewServeMux()
_mux.Handle("/web/", http.StripPrefix("/web/", http.FileServer(http.Dir("/home/miki/"))))
_mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- _r, _err := MakeResourceSig(_fs.FileSystemInfo.RootDir+"/", -1, regexp.MustCompile("^([a-zA-Z0-9.]+).html$"))
+ _r, _err := MakeResourceSig(_fs.FileSystemInfo.WebDir+"/", -1, regexp.MustCompile("^([a-zA-Z0-9.]+).html$"))
if _err != nil {
fmt.Printf("_ERROR\tmain():HandleFunc(\"/\"):MakeResourceSig():%s\n", _err)
http.NotFound(w, r)
@@ -169,6 +176,8 @@ func main() {
fmt.Printf("INFO:\tmain():mux:Resource(%+v)\n", _rPkg)
})
+ /// RUN SERVERS ///
+
if _err := http.ListenAndServeTLS(":"+_si.ServerInfo.Port, _tls_cert_path, _tls_key_path, _mux); _err != nil {
fmt.Printf("_ERROR\tmain():ListenAndServeTLS():%s\n", _err)
}