Skip to content

Commit 9fb23cc

Browse files
committed
fix: update cors env
1 parent 8d2c51a commit 9fb23cc

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

backend/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ARG PORT
99
ARG APP_ENV
1010
ARG CLERK_SECRET_KEY
1111
ARG CLIENT_URL
12+
1213
COPY . .
1314
RUN CGO_ENABLED=0 GOOS=linux go build -o /server ./cmd/server/
1415

backend/cmd/server/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ func main() {
106106
w.WriteHeader(http.StatusOK)
107107
fmt.Fprintln(w, "OK")
108108
})
109-
110-
check(http.ListenAndServe(httpAddress(), corsmiddleware.CORS(mux)))
109+
url:=requiredEnv("CLIENT_URL")
110+
check(http.ListenAndServe(httpAddress(), corsmiddleware.CORS(mux,url)))
111111

112112
}
113113
func check(err error) {

backend/internal/middleware/cors/cors.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package middleware
22

3-
import "net/http"
3+
import
4+
("net/http"
5+
6+
)
7+
8+
func CORS(next http.Handler,url string) http.Handler {
49

5-
func CORS(next http.Handler) http.Handler {
610
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
711

8-
w.Header().Set("Access-Control-Allow-Origin", "http://localhost:5173")
12+
w.Header().Set("Access-Control-Allow-Origin", url)
913

1014
w.Header().Set("Access-Control-Allow-Credentials", "true")
1115

0 commit comments

Comments
 (0)