Created
May 17, 2023 08:17
-
-
Save niorad/ac8822c6ce491e4265e9e117fb59b519 to your computer and use it in GitHub Desktop.
Simple Golang-Server for serving Godot-Web-Exports locally (Needed for Godot 4.0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
) | |
func main() { | |
fs := http.FileServer(http.Dir("./")) | |
http.Handle("/", addHeaders(fs)) | |
fmt.Printf("Server started at port 4567") | |
err := http.ListenAndServe(":4567", nil) | |
if err == nil { | |
log.Fatal(err) | |
} | |
} | |
func addHeaders(fs http.Handler) http.HandlerFunc { | |
return func(w http.ResponseWriter, r *http.Request) { | |
w.Header().Add("X-Frame-Options", "DENY") | |
w.Header().Add("Cross-Origin-Opener-Policy", "same-origin") | |
w.Header().Add("Cross-Origin-Embedder-Policy", "require-corp") | |
w.Header().Add("Cross-Origin-Resource-Policy", "cross-origin") | |
fs.ServeHTTP(w, r) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment