Skip to content

Commit 5ac6e92

Browse files
authored
Merge pull request #6 from commitdev/add-cors
Add a very open cors policy to allow the frontend to hit endpoints
2 parents f2fdcb4 + 4db5dde commit 5ac6e92

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# commit0-deployable-backend
2-
A commit0 module containing a backend that can be deployed to the infrastructure set up using commit0-aws-eks-stack
2+
A commit0 module containing a backend that can be deployed to the infrastructure set up using commit0-aws-eks-stack.
3+
4+
After rendering the template with the `zero` tool, check it into github and run `go mod init github.com/<path on github>`

main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"strconv"
1313
"syscall"
1414
"time"
15+
16+
"github.com/rs/cors"
1517
)
1618

1719
const gracefulShutdownTimeout = 10 * time.Second
@@ -37,8 +39,11 @@ func main() {
3739
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
3840
})
3941

42+
// Change this to a more strict CORS policy
43+
handler := cors.Default().Handler(r)
44+
4045
serverAddress := fmt.Sprintf("0.0.0.0:%s", os.Getenv("SERVER_PORT"))
41-
server := &http.Server{Addr: serverAddress, Handler: r}
46+
server := &http.Server{Addr: serverAddress, Handler: handler}
4247

4348
// Watch for signals to handle graceful shutdown
4449
stop := make(chan os.Signal, 1)

0 commit comments

Comments
 (0)