platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
44
selective-vpn-api/app/domains_handlers_smartdns.go
Normal file
44
selective-vpn-api/app/domains_handlers_smartdns.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// smartdns wildcards
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
func handleSmartdnsWildcards(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
payload := struct {
|
||||
Domains []string `json:"domains"`
|
||||
}{Domains: readSmartDNSWildcardDomains()}
|
||||
writeJSON(w, http.StatusOK, payload)
|
||||
case http.MethodPost:
|
||||
var payload struct {
|
||||
Domains []string `json:"domains"`
|
||||
}
|
||||
if r.Body != nil {
|
||||
defer r.Body.Close()
|
||||
if err := json.NewDecoder(io.LimitReader(r.Body, 1<<20)).Decode(&payload); err != nil {
|
||||
http.Error(w, "bad json", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := saveSmartDNSWildcardDomainsState(payload.Domains); err != nil {
|
||||
http.Error(w, "write error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]string{"status": "ok"})
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func readSmartDNSWildcardDomains() []string {
|
||||
domains, _ := loadSmartDNSWildcardDomainsState(nil)
|
||||
return domains
|
||||
}
|
||||
Reference in New Issue
Block a user