|
@@ -3,8 +3,13 @@ package webserv
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "log"
|
|
|
"net/http"
|
|
|
+ "os"
|
|
|
+ "path/filepath"
|
|
|
"sync"
|
|
|
+
|
|
|
+ "imuslab.com/zoraxy/mod/utils"
|
|
|
)
|
|
|
|
|
|
/*
|
|
@@ -28,6 +33,11 @@ type WebServer struct {
|
|
|
|
|
|
// NewWebServer creates a new WebServer instance.
|
|
|
func NewWebServer(options *WebServerOptions) *WebServer {
|
|
|
+ if !utils.FileExists(options.WebRoot) {
|
|
|
+ //Web root folder not exists. Create one
|
|
|
+ os.MkdirAll(filepath.Join(options.WebRoot, "html"), 0775)
|
|
|
+ os.MkdirAll(filepath.Join(options.WebRoot, "templates"), 0775)
|
|
|
+ }
|
|
|
return &WebServer{
|
|
|
mux: http.NewServeMux(),
|
|
|
option: options,
|
|
@@ -72,7 +82,7 @@ func (ws *WebServer) Start() error {
|
|
|
ws.mux = http.NewServeMux()
|
|
|
|
|
|
//Create a static web server
|
|
|
- fs := http.FileServer(http.Dir(ws.option.WebRoot))
|
|
|
+ fs := http.FileServer(http.Dir(filepath.Join(ws.option.WebRoot, "html")))
|
|
|
ws.mux.Handle("/", ws.fsMiddleware(fs))
|
|
|
|
|
|
ws.server = &http.Server{
|
|
@@ -88,6 +98,7 @@ func (ws *WebServer) Start() error {
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
+ log.Println("Static Web Server started. Listeing on :" + ws.option.Port)
|
|
|
ws.isRunning = true
|
|
|
|
|
|
return nil
|