-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
28 lines (24 loc) · 807 Bytes
/
main.go
File metadata and controls
28 lines (24 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main
import (
"log"
"net/http"
)
func main() {
http.HandleFunc("/apps/", enableCORS(
http.StripPrefix("/apps/github",
http.FileServer(http.Dir("apps/github/dist"))).ServeHTTP))
log.Printf("Serving %s on HTTP port: %d\n", "public", 8082)
log.Fatal(http.ListenAndServe(":8082", nil))
}
func enableCORS(handlerFunc http.HandlerFunc) http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Access-Control-Allow-Origin", "*")
writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE")
writer.Header().Set("Access-Control-Allow-Headers",
"Accept, Content-Type, Content-Length, Accept-Encoding, Authorization")
if request.Method == http.MethodOptions {
return
}
handlerFunc(writer, request)
}
}