From 86c4719b540b96541c5369d24d574a027ba3e34b Mon Sep 17 00:00:00 2001 From: Blaster4385 Date: Tue, 30 Apr 2024 11:13:55 +0530 Subject: feat: switched to backend based redirection --- server/main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'server') diff --git a/server/main.go b/server/main.go index a48611f..1ce935c 100644 --- a/server/main.go +++ b/server/main.go @@ -45,6 +45,7 @@ func RegisterHandlers(e *echo.Echo) { e.Use(middleware.CORS()) e.POST("/bin", postBin) e.GET("/bin/:id", getBin) + e.GET("/r/:id", redirectToURL) } func main() { @@ -96,6 +97,18 @@ func getBin(echoContext echo.Context) error { return echoContext.JSON(http.StatusOK, bin) } +func redirectToURL(echoContext echo.Context) error { + id := echoContext.Param("id") + bin, err := getBinById(id) + if err != nil { + echoContext.Logger().Error(err) + return err + } + + url := bin.Content + return echoContext.Redirect(http.StatusFound, url) +} + func createTable() error { _, err := db.Exec("CREATE TABLE IF NOT EXISTS bins (id TEXT PRIMARY KEY, content TEXT, language TEXT)") return err -- cgit v1.2.3-73-gaa49b