|
|
|
@ -62,6 +62,8 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
|
|
|
|
|
AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete},
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
e.Use(CORSMiddleware())
|
|
|
|
|
|
|
|
|
|
e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{
|
|
|
|
|
Skipper: timeoutSkipper,
|
|
|
|
|
Timeout: 30 * time.Second,
|
|
|
|
@ -184,3 +186,31 @@ func timeoutSkipper(c echo.Context) bool {
|
|
|
|
|
// Skip timeout for blob upload which is frequently timed out.
|
|
|
|
|
return c.Request().Method == http.MethodPost && c.Request().URL.Path == "/api/v1/resource/blob"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CORSMiddleware() echo.MiddlewareFunc {
|
|
|
|
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
|
|
|
return func(c echo.Context) error {
|
|
|
|
|
if grpcRequestSkipper(c) {
|
|
|
|
|
return next(c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r := c.Request()
|
|
|
|
|
w := c.Response().Writer
|
|
|
|
|
|
|
|
|
|
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
|
|
|
|
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
|
|
|
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
|
|
|
|
w.Header().Set("Access-Control-Allow-Credentials", "true")
|
|
|
|
|
|
|
|
|
|
// If it's preflight request, return immediately.
|
|
|
|
|
if r.Method == "OPTIONS" {
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Continue processing request.
|
|
|
|
|
next(c)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|