Add CORS to bskyweb

This commit is contained in:
Jaz Volpert
2024-09-08 04:32:51 +00:00
parent 95aee146b6
commit 200d35e8c9
2 changed files with 14 additions and 0 deletions
+7
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"},
},
}, },
}, },
} }
+7
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
// //