gin icon indicating copy to clipboard operation
gin copied to clipboard

router.Static can not run in https mode

Open chun222 opened this issue 1 year ago • 1 comments

router.Static can not run in https mode ,errors: http: TLS handshake error from [::1]:14521: remote error: tls: unknown certificate

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/unrolled/secure"
)

func main() {
	router := gin.Default()
	router.Use(TlsHandler())

	router.Static("/html", "/html") //Static file handler
	// Ping handler
	router.GET("/ping", func(c *gin.Context) {
		c.String(200, "pong")
	})
	router.RunTLS(":8080", "cert.pem", "key.pem")
}

func TlsHandler() gin.HandlerFunc {
	return func(c *gin.Context) {
		secureMiddleware := secure.New(secure.Options{
			SSLRedirect: true,
			SSLHost:     "localhost:8080",
		})
		err := secureMiddleware.Process(c.Writer, c.Request)

		// If there was an error, do not continue.
		if err != nil {
			return
		}

		c.Next()
	}
}

chun222 avatar Apr 11 '23 15:04 chun222

it means your certficate is not signed, what kind of certificae are you using?

dropdevrahul avatar May 08 '23 12:05 dropdevrahul