Skip to content

Commit

Permalink
Adds CORS headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLeister committed Jan 1, 2019
1 parent 437df52 commit 22c2c4f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ type Config struct {

var conf Config

/*
* Sets CORS headers
*/
func addCORSheaders(w http.ResponseWriter) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "OPTIONS, HEAD, GET, PUT")
w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type")
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Max-Age", "7200")
}


/*
* Request handler
* Is activated when a clients requests the file, file information or an upload
Expand All @@ -57,6 +69,9 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {

fileStorePath := strings.TrimPrefix(u.Path, "/" + conf.UploadSubDir)

// Add CORS headers
addCORSheaders(w)

if r.Method == "PUT" {
// Check if MAC is attached to URL
if a["v"] == nil {
Expand Down

0 comments on commit 22c2c4f

Please sign in to comment.