2020-02-27 14:07:27 +00:00
|
|
|
// +build dev
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
|
|
)
|
|
|
|
|
|
|
|
var StaticDir string = "htdocs/"
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Router().GET("/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
2020-03-01 17:20:16 +00:00
|
|
|
http.ServeFile(w, r, path.Join(StaticDir, "maatma.html"))
|
|
|
|
})
|
|
|
|
Router().GET("/auth", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
http.ServeFile(w, r, path.Join(StaticDir, "maatma.html"))
|
|
|
|
})
|
|
|
|
Router().GET("/domains", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
http.ServeFile(w, r, path.Join(StaticDir, "maatma.html"))
|
|
|
|
})
|
|
|
|
Router().GET("/tunnels", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
http.ServeFile(w, r, path.Join(StaticDir, "maatma.html"))
|
2020-02-27 14:07:27 +00:00
|
|
|
})
|
|
|
|
Router().GET("/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
serveStaticAsset(w, r)
|
|
|
|
})
|
|
|
|
Router().GET("/fonts/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
serveStaticAsset(w, r)
|
|
|
|
})
|
|
|
|
Router().GET("/img/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
serveStaticAsset(w, r)
|
|
|
|
})
|
|
|
|
Router().GET("/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
serveStaticAsset(w, r)
|
|
|
|
})
|
|
|
|
Router().GET("/views/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
serveStaticAsset(w, r)
|
|
|
|
})
|
|
|
|
|
|
|
|
Router().GET("/dashboard/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
http.ServeFile(w, r, path.Join(StaticDir, "dashboard.html"))
|
|
|
|
})
|
2020-02-28 12:23:11 +00:00
|
|
|
Router().GET("/dashboard/:where", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
2020-04-26 21:56:44 +00:00
|
|
|
http.ServeFile(w, r, path.Join(StaticDir, "dashboard.html"))
|
2020-02-27 14:07:27 +00:00
|
|
|
})
|
2020-02-28 12:23:11 +00:00
|
|
|
Router().GET("/dashboard/:where/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
2020-02-27 14:07:27 +00:00
|
|
|
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/dashboard")
|
|
|
|
serveStaticAsset(w, r)
|
|
|
|
})
|
|
|
|
|
|
|
|
flag.StringVar(&StaticDir, "static", StaticDir, "Directory containing static files")
|
|
|
|
}
|
|
|
|
|
|
|
|
func serveStaticAsset(w http.ResponseWriter, r *http.Request) {
|
|
|
|
http.StripPrefix("/", http.FileServer(http.Dir(StaticDir))).ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func sanitizeStaticOptions() error {
|
|
|
|
StaticDir, _ := filepath.Abs(StaticDir)
|
|
|
|
if _, err := os.Stat(StaticDir); os.IsNotExist(err) {
|
|
|
|
StaticDir, _ = filepath.Abs(filepath.Join(filepath.Dir(os.Args[0]), "htdocs"))
|
|
|
|
if _, err := os.Stat(StaticDir); os.IsNotExist(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|