Skip to content

Commit

Permalink
added cors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanogame committed Jun 28, 2023
1 parent 7591f7b commit 2794cf8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions HttpServer/HttpHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type LoadLocations struct {

func (Location *StaticLocations) HandleStatic(config *utils.Http) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
enableCors(&w)
if config != nil && r.URL.Path != Location.WebPath {
http.ServeFile(w, r, config.File404)
return
Expand All @@ -32,6 +33,7 @@ func (Location *StaticLocations) HandleStatic(config *utils.Http) http.HandlerFu

func (Location *ProxyLocations) HandleProxy(config *utils.Http) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
enableCors(&w)
if config != nil && r.URL.Path != Location.WebPath {
http.ServeFile(w, r, config.File404)
return
Expand Down
4 changes: 4 additions & 0 deletions HttpServer/HttpReqestManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"net/http"
)

func enableCors(w *http.ResponseWriter) {
(*w).Header().Set("Access-Control-Allow-Origin", "*")
}

func StartHttpServer(port string, locations *utils.Locations, config *utils.Http) {
locationHandler(locations, config)
fmt.Println("Http server started and listening at: ", port)
Expand Down
1 change: 1 addition & 0 deletions HttpServer/LoadHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func (Location *LoadLocations) HandleLoad(config *utils.Http) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
enableCors(&w)
if config != nil && r.URL.Path != Location.WebPath {
http.ServeFile(w, r, config.File404)
return
Expand Down

0 comments on commit 2794cf8

Please sign in to comment.