do not pass http.ResponseWriter as pointer to EnableCors (#1440)

This commit is contained in:
Tim Cooper
2021-10-01 14:40:13 -05:00
committed by GitHub
parent fa77f6396d
commit fe47c99ac2
6 changed files with 9 additions and 9 deletions

View File

@@ -12,7 +12,7 @@ import (
// ExternalGetChatMessages gets all of the chat messages. // ExternalGetChatMessages gets all of the chat messages.
func ExternalGetChatMessages(integration user.ExternalAPIUser, w http.ResponseWriter, r *http.Request) { func ExternalGetChatMessages(integration user.ExternalAPIUser, w http.ResponseWriter, r *http.Request) {
middleware.EnableCors(&w) middleware.EnableCors(w)
GetChatMessages(w, r) GetChatMessages(w, r)
} }

View File

@@ -29,7 +29,7 @@ type webConfigResponse struct {
// GetWebConfig gets the status of the server. // GetWebConfig gets the status of the server.
func GetWebConfig(w http.ResponseWriter, r *http.Request) { func GetWebConfig(w http.ResponseWriter, r *http.Request) {
middleware.EnableCors(&w) middleware.EnableCors(w)
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
pageContent := utils.RenderPageContentMarkdown(data.GetExtraPageBodyContent()) pageContent := utils.RenderPageContentMarkdown(data.GetExtraPageBodyContent())
@@ -68,7 +68,7 @@ func GetWebConfig(w http.ResponseWriter, r *http.Request) {
// GetAllSocialPlatforms will return a list of all social platform types. // GetAllSocialPlatforms will return a list of all social platform types.
func GetAllSocialPlatforms(w http.ResponseWriter, r *http.Request) { func GetAllSocialPlatforms(w http.ResponseWriter, r *http.Request) {
middleware.EnableCors(&w) middleware.EnableCors(w)
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
platforms := models.GetAllSocialHandles() platforms := models.GetAllSocialHandles()

View File

@@ -45,6 +45,6 @@ func HandleHLSRequest(w http.ResponseWriter, r *http.Request) {
cacheTime := utils.GetCacheDurationSecondsForPath(relativePath) cacheTime := utils.GetCacheDurationSecondsForPath(relativePath)
w.Header().Set("Cache-Control", "public, max-age="+strconv.Itoa(cacheTime)) w.Header().Set("Cache-Control", "public, max-age="+strconv.Itoa(cacheTime))
} }
middleware.EnableCors(&w) middleware.EnableCors(w)
http.ServeFile(w, r, fullPath) http.ServeFile(w, r, fullPath)
} }

View File

@@ -34,7 +34,7 @@ type MetadataPage struct {
// IndexHandler handles the default index route. // IndexHandler handles the default index route.
func IndexHandler(w http.ResponseWriter, r *http.Request) { func IndexHandler(w http.ResponseWriter, r *http.Request) {
middleware.EnableCors(&w) middleware.EnableCors(w)
isIndexRequest := r.URL.Path == "/" || filepath.Base(r.URL.Path) == "index.html" || filepath.Base(r.URL.Path) == "" isIndexRequest := r.URL.Path == "/" || filepath.Base(r.URL.Path) == "index.html" || filepath.Base(r.URL.Path) == ""
// For search engine bots and social scrapers return a special // For search engine bots and social scrapers return a special

View File

@@ -11,7 +11,7 @@ import (
// GetStatus gets the status of the server. // GetStatus gets the status of the server.
func GetStatus(w http.ResponseWriter, r *http.Request) { func GetStatus(w http.ResponseWriter, r *http.Request) {
middleware.EnableCors(&w) middleware.EnableCors(w)
status := core.GetStatus() status := core.GetStatus()
response := webStatusResponse{ response := webStatusResponse{

View File

@@ -4,7 +4,7 @@ import (
"net/http" "net/http"
) )
// EnableCors enables the cors header on the responses. // EnableCors enables the CORS header on the responses.
func EnableCors(w *http.ResponseWriter) { func EnableCors(w http.ResponseWriter) {
(*w).Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Origin", "*")
} }