updated 'config.ini'
This commit is contained in:
parent
28f71271d7
commit
be4f86580e
13 changed files with 635 additions and 208 deletions
53
main.go
53
main.go
|
@ -210,22 +210,45 @@ func parsePageParameter(pageStr string) int {
|
|||
}
|
||||
|
||||
func runServer() {
|
||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
http.HandleFunc("/", handleSearch)
|
||||
http.HandleFunc("/search", handleSearch)
|
||||
http.HandleFunc("/suggestions", handleSuggestions)
|
||||
// The /imgproxy handler is deprecated, now its handled by /image/
|
||||
// http.HandleFunc("/imgproxy", handleImageProxy)
|
||||
http.HandleFunc("/node", handleNodeRequest)
|
||||
http.HandleFunc("/settings", handleSettings)
|
||||
http.HandleFunc("/save-settings", handleSaveSettings)
|
||||
http.HandleFunc("/image/", handleImageServe)
|
||||
http.HandleFunc("/image_status", handleImageStatus)
|
||||
http.HandleFunc("/opensearch.xml", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/opensearchdescription+xml")
|
||||
http.ServeFile(w, r, "static/opensearch.xml")
|
||||
})
|
||||
|
||||
if config.WebsiteEnabled {
|
||||
// Website-related endpoints
|
||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
http.HandleFunc("/", handleSearch)
|
||||
http.HandleFunc("/search", handleSearch)
|
||||
http.HandleFunc("/suggestions", handleSuggestions)
|
||||
http.HandleFunc("/settings", handleSettings)
|
||||
http.HandleFunc("/save-settings", handleSaveSettings)
|
||||
http.HandleFunc("/image/", handleImageServe)
|
||||
http.HandleFunc("/image_status", handleImageStatus)
|
||||
http.HandleFunc("/opensearch.xml", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/opensearchdescription+xml")
|
||||
http.ServeFile(w, r, "static/opensearch.xml")
|
||||
})
|
||||
printInfo("Website functionality enabled.")
|
||||
} else {
|
||||
// Redirect all website routes to a "service disabled" handler
|
||||
http.HandleFunc("/static/", handleWebsiteDisabled)
|
||||
http.HandleFunc("/", handleWebsiteDisabled)
|
||||
http.HandleFunc("/search", handleWebsiteDisabled)
|
||||
http.HandleFunc("/settings", handleWebsiteDisabled)
|
||||
http.HandleFunc("/save-settings", handleWebsiteDisabled)
|
||||
http.HandleFunc("/image/", handleWebsiteDisabled)
|
||||
http.HandleFunc("/image_status", handleWebsiteDisabled)
|
||||
http.HandleFunc("/opensearch.xml", handleWebsiteDisabled)
|
||||
printInfo("Website functionality disabled.")
|
||||
}
|
||||
|
||||
if config.NodesEnabled {
|
||||
http.HandleFunc("/node", handleNodeRequest)
|
||||
}
|
||||
|
||||
printMessage("Server is listening on http://localhost:%d", config.Port)
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", config.Port), nil))
|
||||
}
|
||||
|
||||
func handleWebsiteDisabled(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
_, _ = w.Write([]byte("The website functionality is currently disabled."))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue