commit 095331b5a996b6c9156e140fc581b6eb760008dc
parent 155f3d3ef00a82f0cb448305ba6ad2c7c13bf780
Author: vx-clutch <[email protected]>
Date: Tue, 2 Dec 2025 21:44:14 -0500
cd into project dir
Diffstat:
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/server/server.go b/src/server/server.go
@@ -27,7 +27,7 @@ type reqData struct {
func handleDir(entries []os.DirEntry, wwwDir string, routes map[string]string, base string) error {
for _, entry := range entries {
if entry.IsDir() {
- sub := filepath.Join(wwwDir, entry.Name())
+ sub := filepath.Join("www", entry.Name())
subs, err := os.ReadDir(sub)
if err != nil {
return fmt.Errorf("failed to read %s: %w", sub, err)
@@ -45,7 +45,7 @@ func handleDir(entries []os.DirEntry, wwwDir string, routes map[string]string, b
}
if strings.HasSuffix(entry.Name(), ".lua") {
name := strings.TrimSuffix(entry.Name(), ".lua")
- path := filepath.Join(wwwDir, entry.Name())
+ path := filepath.Join("www", entry.Name())
if name == "index" {
if base == "" {
routes["/"] = path
@@ -248,7 +248,10 @@ func loadLua(luaDir string, entry string, cfg *config.MyConfig, requestData reqD
}
func Start(dir string) error {
- tomlDocument, err := os.ReadFile(filepath.Join(dir, "Fes.toml"))
+ os.Chdir(dir)
+ dir = "."
+
+ tomlDocument, err := os.ReadFile("Fes.toml")
if err != nil {
return err
}
@@ -259,8 +262,7 @@ func Start(dir string) error {
return fmt.Errorf("failed to parse Fes.toml: %w", err)
}
- wwwDir := filepath.Join(dir, "www")
- entries, err := os.ReadDir(wwwDir)
+ entries, err := os.ReadDir("www")
if err != nil {
return fmt.Errorf("failed to read www directory: %w", err)
}
@@ -274,13 +276,13 @@ func Start(dir string) error {
</body>
</html>
`
- if _, err := os.Stat(filepath.Join(wwwDir, "404.lua")); err == nil {
- notFoundData, err = loadLua(dir, filepath.Join(wwwDir, "404.lua"), &cfg, reqData{})
+ if _, err := os.Stat(filepath.Join("www", "404.lua")); err == nil {
+ notFoundData, err = loadLua(dir, "www/404.lua", &cfg, reqData{})
if err != nil {
panic(err)
}
- } else if _, err := os.Stat(filepath.Join(wwwDir, "404.html")); err == nil {
- buf, err := os.ReadFile(filepath.Join(wwwDir, "404.html"))
+ } else if _, err := os.Stat("www/404.html"); err == nil {
+ buf, err := os.ReadFile("www/404.html")
if err != nil {
panic(err)
}
@@ -288,7 +290,7 @@ func Start(dir string) error {
}
routes := make(map[string]string)
- handleDir(entries, wwwDir, routes, "")
+ handleDir(entries, "www", routes, "")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path