fix: keep legacy subscription URLs working
This commit is contained in:
1 parent
d0ef13b4a5
commit
5693beea46
1 file changed
+14
-12
@@ -13,8 +13,8 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func RegisterPublicSubscriptionRoutes(api *gin.RouterGroup, db *gorm.DB, cfg *config.Config) {
|
||||
handler := func(c *gin.Context) {
|
||||
func subscriptionHandler(db *gorm.DB, cfg *config.Config) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "database is not configured"})
|
||||
return
|
||||
@@ -83,20 +83,22 @@ func RegisterPublicSubscriptionRoutes(api *gin.RouterGroup, db *gorm.DB, cfg *co
|
||||
c.Header("Cache-Control", "no-store")
|
||||
c.Data(http.StatusOK, "text/plain; charset=utf-8", converted)
|
||||
}
|
||||
}
|
||||
|
||||
// Keep the current canonical API path and accept legacy subscription URLs
|
||||
// so existing clients do not start returning 404 after an upgrade.
|
||||
func RegisterPublicSubscriptionRoutes(api *gin.RouterGroup, db *gorm.DB, cfg *config.Config) {
|
||||
handler := subscriptionHandler(db, cfg)
|
||||
api.GET("/client/sub/:token", handler)
|
||||
api.GET("/client/sub/:token/", handler)
|
||||
}
|
||||
|
||||
// Legacy paths are registered on the engine root by SetupRouterWithDeps.
|
||||
// The aliases below are attached to the same handler through the parent
|
||||
// router group so all subscription URLs share exactly the same behavior.
|
||||
root := api.Group("/")
|
||||
root.GET("/sub/:token", handler)
|
||||
root.GET("/sub/:token/", handler)
|
||||
root.GET("/api/client/sub/:token", handler)
|
||||
root.GET("/api/client/sub/:token/", handler)
|
||||
// RegisterLegacySubscriptionRoutes keeps subscription links generated by
|
||||
// older releases working after upgrading to the /api/v1 route layout.
|
||||
func RegisterLegacySubscriptionRoutes(r *gin.Engine, db *gorm.DB, cfg *config.Config) {
|
||||
handler := subscriptionHandler(db, cfg)
|
||||
r.GET("/sub/:token", handler)
|
||||
r.GET("/sub/:token/", handler)
|
||||
r.GET("/api/client/sub/:token", handler)
|
||||
r.GET("/api/client/sub/:token/", handler)
|
||||
}
|
||||
|
||||
func writeSubInfo(c *gin.Context, db *gorm.DB, tok string) {
|
||||
|
||||
Reference in new issue
Block a user