From 7697d9ea3e9296b5f9fcfed9ea6fd5d2be1d9f39 Mon Sep 17 00:00:00 2001 From: Akilan Date: Fri, 14 Oct 2022 22:00:09 +0400 Subject: [PATCH] page fix --- README.md | 2 +- main.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5a18f70..34ef60f 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Usage of ./WebGatewayUpload: ## Routes - (GET) `/upload` (Opens upload page in the webgateway) -- (POST) `/upload` (Uploads file to peernet from Webpage) +- (POST) `/uploadFile` (Uploads file to peernet from Webpage) - (POST) `/uploadCurl` (Uploads file from CURL) Ex: diff --git a/main.go b/main.go index bf756de..6418e2f 100644 --- a/main.go +++ b/main.go @@ -230,15 +230,19 @@ func main() { r.LoadHTMLGlob("templates/*.html") r.Static("/templates", "./templates") - // Middleware rate limiter + // --------------------------------- Middleware rate limiter ----------------------------------- lm := limiter.NewRateLimiter(time.Minute, 2, func(ctx *gin.Context) (string, error) { return "", nil }) + // --------------------------------------------------------------------------------------------- + // ---------------------------------------- Routes --------------------------------------------- + // GET /upload to open upload page from webgateway r.GET("/upload", lm.Middleware(), func(c *gin.Context) { c.HTML(http.StatusOK, "upload.html", nil) }) + // POST /uploadFile Uploads file to peernet from Webgateway r.POST("/uploadFile", lm.Middleware(), func(c *gin.Context) { file, header, err := c.Request.FormFile("file") defer file.Close() @@ -257,7 +261,7 @@ func main() { "filename": header.Filename, "size": header.Size, "link": "https://peer.ae/" + hex.EncodeToString(publicKey.SerializeCompressed()) + "/" + hex.EncodeToString(warehouseResult.Hash), - "address": BackendAddressWithHTTP, + "address": *WebpageAddress, }) }) @@ -282,12 +286,18 @@ func main() { c.Data(http.StatusOK, "plain/text", []byte(link)) }) + // --------------------------------------------------------------------------------------------- + + // ---------------------------------- Start Gin server ----------------------------------------- // check if SSL is used or not if *SSL { BackendAddressWithHTTP = "https://" + *BackEndApiAddress r.RunTLS(*WebpageAddress, *Certificate, *Key) + *WebpageAddress = "https://" + *WebpageAddress } else { BackendAddressWithHTTP = "http://" + *BackEndApiAddress r.Run(*WebpageAddress) + *WebpageAddress = "http://" + *WebpageAddress } + // --------------------------------------------------------------------------------------------- }