Skip to content

Commit

Permalink
response header
Browse files Browse the repository at this point in the history
  • Loading branch information
baiqll committed Oct 6, 2024
1 parent 6b67067 commit 186c7f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,17 @@ func main() {

}

func http_write(w http.ResponseWriter, res_data []byte){
func set_response_header(w http.ResponseWriter){
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
w.Header().Set("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
w.Header().Set("Access-Control-Allow-Credentials", "true")
}

func http_write(w http.ResponseWriter, res_data []byte){

set_response_header(w)
w.Write(res_data)
}

Expand Down Expand Up @@ -187,7 +192,7 @@ func http_server(server string, tls_crt string, tls_key string, payload string,

}else{
// 文件系统

set_response_header(w)
http.FileServer(http.Dir("./")).ServeHTTP(w, r)

}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewDNS(domain string)(is_new bool){

is_new = true

cmd := exec.Command("sh", "-c", fmt.Sprintf("echo '127.0.0.1 %s' | sudo tee -a /etc/hosts > /dev/null",domain))
cmd := exec.Command("sh", "-c", fmt.Sprintf("echo '127.0.0.1 %s # src-http' | sudo tee -a /etc/hosts > /dev/null",domain))
_, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(err)
Expand Down

0 comments on commit 186c7f6

Please sign in to comment.