feat: version 2.1

This commit is contained in:
Arkaprabha Chakraborty
2026-02-13 00:01:00 +05:30
parent 005838045a
commit 2a46aa7d79
13 changed files with 548 additions and 63 deletions

View File

@@ -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)