Skip to content

Commit 1b94a25

Browse files
enh: enable cors for the server companion (#10)
1 parent 51554eb commit 1b94a25

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
- "**.md"
1212

1313
env:
14-
GO_VERSION: "1.23.4" # https://go.dev/dl/
15-
GOLANGCI_LINT_VERSION: "v1.62.2" # https://github.com/golangci/golangci-lint/releases
14+
GO_VERSION: "1.24.1" # https://go.dev/dl/
15+
GOLANGCI_LINT_VERSION: "v1.64.7" # https://github.com/golangci/golangci-lint/releases
1616

1717
jobs:
1818
lint:

backend-challenge/readme.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ you make.
2828

2929
Functional requirements:
3030

31-
- [ ] Clients should be able to uniquely identify themselves with a phone number
32-
(without authentication)
33-
- [ ] Clients should be able to send messages to other clients, identified by their
34-
phone number
35-
- [ ] Clients should be able to list their chats
31+
- [ ] Clients should be able to uniquely identify themselves
32+
- [ ] Clients should be able to send messages to other clients
33+
- [ ] Clients should be able to list all their chats
3634
- [ ] Clients should be able to list all messages in a chat
3735

3836
## Bonus

client-challenge/server/go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
module github.com/interfaceinc/challenges/ios-engineer/server
22

3-
go 1.22.5
3+
go 1.24.1
44

55
require (
6-
github.com/go-chi/chi/v5 v5.2.0
6+
github.com/go-chi/chi/v5 v5.2.1
7+
github.com/go-chi/cors v1.2.1
78
github.com/go-chi/render v1.0.3
89
github.com/google/uuid v1.6.0
910
github.com/r3labs/sse/v2 v2.10.0
10-
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
11+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394
1112
)
1213

1314
require (
1415
github.com/ajg/form v1.5.1 // indirect
15-
golang.org/x/net v0.33.0 // indirect
16+
golang.org/x/net v0.37.0 // indirect
1617
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
1718
)

client-challenge/server/go.sum

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
22
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
33
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
44
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/go-chi/chi/v5 v5.2.0 h1:Aj1EtB0qR2Rdo2dG4O94RIU35w2lvQSj6BRA4+qwFL0=
6-
github.com/go-chi/chi/v5 v5.2.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
5+
github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8=
6+
github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
7+
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
8+
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
79
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
810
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
911
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -16,11 +18,11 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
1618
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1719
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1820
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
19-
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo=
20-
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
21+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=
22+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM=
2123
golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
22-
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
23-
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
24+
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
25+
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
2426
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
2527
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
2628
gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y=

client-challenge/server/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/go-chi/chi/v5"
1616
"github.com/go-chi/chi/v5/middleware"
17+
"github.com/go-chi/cors"
1718
"github.com/go-chi/render"
1819
"github.com/google/uuid"
1920
"github.com/r3labs/sse/v2"
@@ -45,6 +46,14 @@ func main() {
4546
r.Use(middleware.Logger)
4647
r.Use(middleware.Recoverer)
4748
r.Use(middleware.Timeout(30 * time.Second))
49+
r.Use(cors.Handler(cors.Options{
50+
AllowOriginFunc: func(r *http.Request, origin string) bool { return true },
51+
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
52+
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token", "Idempotency-Key"},
53+
ExposedHeaders: []string{"Link"},
54+
AllowCredentials: true,
55+
MaxAge: 300, // Maximum value not ignored by any of major browsers
56+
}))
4857

4958
r.Handle("/events", http.HandlerFunc(events.ServeHTTP))
5059

0 commit comments

Comments
 (0)