You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

78 lines
1.3 KiB

package Webserver
import (
"net/http"
"path/filepath"
"PersonalWebsite/Variables"
"github.com/gorilla/mux"
)
var (
WebRoot string
)
func init() {
WebRoot = filepath.Join(
Variables.ProjectRoot,
"/web",
)
}
func webRootJoin(p string) string {
return filepath.Join(
WebRoot,
p,
)
}
func Start() error {
var (
r *mux.Router
e error
)
r = mux.NewRouter()
// For images / anything static
r.PathPrefix("/static/").Handler(
http.StripPrefix("/static/",
http.FileServer(http.Dir(webRootJoin("static"))),
),
)
// Handle CSS
r.PathPrefix("/css/").Handler(
http.StripPrefix("/css/",
http.FileServer(http.Dir(webRootJoin("css"))),
),
)
// Handle JS
r.PathPrefix("/js/").Handler(
http.StripPrefix("/js/",
http.FileServer(http.Dir(webRootJoin("js"))),
),
)
// Interface endpoints
r.HandleFunc("/", ViewIndex)
r.HandleFunc("/programming", ViewPostListProgramming)
r.HandleFunc("/pentesting", ViewPostListPentesting)
r.HandleFunc("/post/{id}", ViewPost)
// Administration
r.HandleFunc("/admin", AdminView)
r.HandleFunc("/admin/login", AdminLogin)
r.HandleFunc("/admin/logout", AdminLogout)
r.HandleFunc("/admin/post/new", AdminNewPost)
r.HandleFunc("/admin/post/{id}/edit", AdminEditPost)
e = http.ListenAndServe(Variables.WebserverHost, r)
if e != nil {
return e
}
return nil
}