package main import ( "TheAdversary/api" "TheAdversary/config" "TheAdversary/database" "TheAdversary/server" "fmt" "github.com/gorilla/mux" "net/http" "path/filepath" ) func main() { r := mux.NewRouter() r.StrictSlash(true) r.HandleFunc("/api/login", api.Login).Methods(http.MethodPost) r.HandleFunc("/api/authors", api.Authors).Methods(http.MethodGet) r.HandleFunc("/api/tags", api.Tags).Methods(http.MethodGet) r.HandleFunc("/api/recent", api.Recent).Methods(http.MethodGet) r.HandleFunc("/api/search", api.Search).Methods(http.MethodGet) r.HandleFunc("/api/upload", api.Upload).Methods(http.MethodPost) r.HandleFunc("/api/edit", api.Edit).Methods(http.MethodPost) r.HandleFunc("/api/delete", api.Delete).Methods(http.MethodPost) r.HandleFunc("/api/assets", api.Assets).Methods(http.MethodGet, http.MethodPost, http.MethodDelete) r.HandleFunc("/article/{article}", server.Article).Methods(http.MethodGet) r.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, filepath.Join(config.FrontendDir, "img", "logodark.svg")) }) r.PathPrefix("/sass/").HandlerFunc(server.ServePath) r.PathPrefix("/img/").HandlerFunc(server.ServePath) r.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { http.ServeFile(w, r, filepath.Join(config.FrontendDir, "html", "landingpage.html")) } else { server.Error404(w, r) } }) db, err := database.NewSqlite3Connection(config.DatabaseFile) if err != nil { panic(err) } database.SetGlobDB(db) if err := http.ListenAndServe(fmt.Sprintf(":%s", config.ServerPort), r); err != nil { panic(err) } }