mirror of
https://github.com/arkorty/Reduce.git
synced 2026-03-18 00:47:10 +00:00
feat: version 2.1
This commit is contained in:
@@ -15,13 +15,20 @@ func main() {
|
||||
|
||||
e := echo.New()
|
||||
|
||||
// Frontend URL for CORS
|
||||
frontendURL := os.Getenv("BASE_URL")
|
||||
if frontendURL == "" {
|
||||
frontendURL = "http://localhost:5173"
|
||||
}
|
||||
|
||||
// Middleware
|
||||
e.Use(middleware.Logger())
|
||||
e.Use(middleware.Recover())
|
||||
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
||||
AllowOrigins: []string{"*"},
|
||||
AllowMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete},
|
||||
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept, echo.HeaderAuthorization},
|
||||
AllowOrigins: []string{frontendURL},
|
||||
AllowMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete},
|
||||
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept, echo.HeaderAuthorization},
|
||||
AllowCredentials: true,
|
||||
}))
|
||||
|
||||
// Health
|
||||
@@ -32,12 +39,20 @@ func main() {
|
||||
// Auth
|
||||
e.POST("/auth/register", register)
|
||||
e.POST("/auth/login", login)
|
||||
e.POST("/auth/logout", logout)
|
||||
e.GET("/auth/me", getMe, JWTMiddleware)
|
||||
|
||||
// User account management
|
||||
user := e.Group("/user", JWTMiddleware)
|
||||
user.GET("/stats", getUserStats)
|
||||
user.PUT("/username", updateUsername)
|
||||
user.PUT("/password", updatePassword)
|
||||
user.DELETE("/account", deleteAccount)
|
||||
|
||||
// Public link routes (optional auth for shorten)
|
||||
e.POST("/reduce/shorten", shortenURL, OptionalJWTMiddleware)
|
||||
e.GET("/reduce/:code", fetchLURL)
|
||||
e.POST("/reduce/:code/verify", verifyAndRedirect)
|
||||
e.POST("/shorten", shortenURL, OptionalJWTMiddleware)
|
||||
e.GET("/:code", fetchLURL, OptionalJWTMiddleware)
|
||||
e.POST("/:code/verify", verifyAndRedirect)
|
||||
|
||||
// Authenticated link management
|
||||
links := e.Group("/links", JWTMiddleware)
|
||||
|
||||
Reference in New Issue
Block a user