Skip to content

Instantly share code, notes, and snippets.

@niorad
Created May 17, 2023 08:17
Show Gist options
  • Save niorad/ac8822c6ce491e4265e9e117fb59b519 to your computer and use it in GitHub Desktop.
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)
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