Add CORS to bskyweb (#5221)

zio/stable
Jaz 2024-09-09 10:39:28 -07:00 committed by GitHub
parent f240893980
commit 9e1eb1f9f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -80,6 +80,13 @@ func run(args []string) {
Value: "", Value: "",
EnvVars: []string{"BASIC_AUTH_PASSWORD"}, EnvVars: []string{"BASIC_AUTH_PASSWORD"},
}, },
&cli.StringSliceFlag{
Name: "cors-allowed-origins",
Usage: "list of allowed origins for CORS requests",
Required: false,
Value: cli.NewStringSlice("https://bsky.app", "https://main.bsky.dev", "https://app.staging.bsky.dev"),
EnvVars: []string{"CORS_ALLOWED_ORIGINS"},
},
}, },
}, },
} }

View File

@ -57,6 +57,7 @@ func serve(cctx *cli.Context) error {
linkHost := cctx.String("link-host") linkHost := cctx.String("link-host")
ipccHost := cctx.String("ipcc-host") ipccHost := cctx.String("ipcc-host")
basicAuthPassword := cctx.String("basic-auth-password") basicAuthPassword := cctx.String("basic-auth-password")
corsOrigins := cctx.StringSlice("cors-allowed-origins")
// Echo // Echo
e := echo.New() e := echo.New()
@ -168,6 +169,12 @@ func serve(cctx *cli.Context) error {
RedirectCode: http.StatusFound, RedirectCode: http.StatusFound,
})) }))
// CORS middleware
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: corsOrigins,
AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodOptions},
}))
// //
// configure routes // configure routes
// //