Added HTTPS redirect and linter settings
This commit is contained in:
parent
52cd0a2f09
commit
0e4f7fe6ec
3
.golangci.yml
Normal file
3
.golangci.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
run:
|
||||||
|
skip-dirs:
|
||||||
|
components
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.12
|
|||||||
require (
|
require (
|
||||||
cloud.google.com/go v0.39.0 // indirect
|
cloud.google.com/go v0.39.0 // indirect
|
||||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
||||||
github.com/aerogo/aero v1.3.11
|
github.com/aerogo/aero v1.3.14
|
||||||
github.com/aerogo/api v0.2.0
|
github.com/aerogo/api v0.2.0
|
||||||
github.com/aerogo/crawler v0.2.5
|
github.com/aerogo/crawler v0.2.5
|
||||||
github.com/aerogo/flow v0.1.4
|
github.com/aerogo/flow v0.1.4
|
||||||
|
2
go.sum
2
go.sum
@ -13,6 +13,8 @@ github.com/a8m/mark v0.1.1-0.20170507133748-44f2db618845/go.mod h1:c8Mh99Cw82nrs
|
|||||||
github.com/aerogo/aero v1.3.1/go.mod h1:5rPhXo2DNMFQ7XhDsuZ3L7Zr6TH/349+WczUbrOUZvM=
|
github.com/aerogo/aero v1.3.1/go.mod h1:5rPhXo2DNMFQ7XhDsuZ3L7Zr6TH/349+WczUbrOUZvM=
|
||||||
github.com/aerogo/aero v1.3.11 h1:3kg6cPDwH6/ul6ZU4JMLKJsPaaBGTxy+LzV8lgTW6n0=
|
github.com/aerogo/aero v1.3.11 h1:3kg6cPDwH6/ul6ZU4JMLKJsPaaBGTxy+LzV8lgTW6n0=
|
||||||
github.com/aerogo/aero v1.3.11/go.mod h1:iTwPGnf6L6G6+FdvnNHoYyIRk2mDOV2JqI7pqqk9RYM=
|
github.com/aerogo/aero v1.3.11/go.mod h1:iTwPGnf6L6G6+FdvnNHoYyIRk2mDOV2JqI7pqqk9RYM=
|
||||||
|
github.com/aerogo/aero v1.3.14 h1:Zxx1Wh/OpjujVMUVmMOjZi8jAQAEUWvtnobtXJDZ5ak=
|
||||||
|
github.com/aerogo/aero v1.3.14/go.mod h1:iTwPGnf6L6G6+FdvnNHoYyIRk2mDOV2JqI7pqqk9RYM=
|
||||||
github.com/aerogo/api v0.2.0 h1:mIc/y381e+Qc85eSc2cKPdpDDOmT0hlnEeCw2Dcf7no=
|
github.com/aerogo/api v0.2.0 h1:mIc/y381e+Qc85eSc2cKPdpDDOmT0hlnEeCw2Dcf7no=
|
||||||
github.com/aerogo/api v0.2.0/go.mod h1:6objJn5XiKpYpywQUPrFjxZIXD4NVI2LwcBNYCEcS3Y=
|
github.com/aerogo/api v0.2.0/go.mod h1:6objJn5XiKpYpywQUPrFjxZIXD4NVI2LwcBNYCEcS3Y=
|
||||||
github.com/aerogo/cluster v0.1.6 h1:9HYjJwo19uuh9thIc80T3caap9t9b4BXZ1iN8aztjlU=
|
github.com/aerogo/cluster v0.1.6 h1:9HYjJwo19uuh9thIc80T3caap9t9b4BXZ1iN8aztjlU=
|
||||||
|
1
main.go
1
main.go
@ -46,6 +46,7 @@ func configure(app *aero.Application) *aero.Application {
|
|||||||
// Middleware
|
// Middleware
|
||||||
app.Use(
|
app.Use(
|
||||||
middleware.Recover,
|
middleware.Recover,
|
||||||
|
middleware.HTTPSRedirect,
|
||||||
middleware.OpenGraph,
|
middleware.OpenGraph,
|
||||||
middleware.Log,
|
middleware.Log,
|
||||||
middleware.Session,
|
middleware.Session,
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
// // HTTPSRedirect middleware redirects to HTTPS if needed.
|
import (
|
||||||
// func HTTPSRedirect() aero.Middleware {
|
"net/http"
|
||||||
// return func(ctx aero.Context, next func()) {
|
|
||||||
// request := ctx.Request()
|
|
||||||
// userAgent := request.Header().Get("User-Agent")
|
|
||||||
// isBrowser := strings.Contains(userAgent, "Mozilla/") || strings.Contains(userAgent, "Chrome/") || strings.Contains(userAgent, "AppleWebKit/")
|
|
||||||
|
|
||||||
// if !strings.HasPrefix(request.Protocol(), "HTTP/2") && isBrowser {
|
"github.com/aerogo/aero"
|
||||||
// fmt.Println("Redirect to HTTPS")
|
)
|
||||||
// ctx.Redirect(http.StatusTemporaryRedirect, "https://" + request.Host() + request.URL().Path)
|
|
||||||
// ctx.Response().WriteHeader(ctx.Status())
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Handle the request
|
// HTTPSRedirect middleware redirects to HTTPS if needed.
|
||||||
// next()
|
func HTTPSRedirect(next aero.Handler) aero.Handler {
|
||||||
// }
|
return func(ctx aero.Context) error {
|
||||||
// }
|
request := ctx.Request()
|
||||||
|
userAgent := request.Header("User-Agent")
|
||||||
|
isBrowser := userAgent != ""
|
||||||
|
|
||||||
|
if isBrowser && request.Scheme() != "https" {
|
||||||
|
return ctx.Redirect(http.StatusPermanentRedirect, "https://"+request.Host()+request.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the request
|
||||||
|
return next(ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user