48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
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/upload", api.Upload).Methods(http.MethodPost)
|
|
r.HandleFunc("/api/recent", api.Recent).Methods(http.MethodGet)
|
|
r.HandleFunc("/api/search", api.Search).Methods(http.MethodGet)
|
|
|
|
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)
|
|
}
|
|
}
|