Skip to content

Commit 5505737

Browse files
committed
Set middlewars
1 parent c2aa344 commit 5505737

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
2-
*.iml
2+
*.iml
3+
echo-cms

config/config.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ func LoadConfig() {
1818
}
1919

2020
type SiteHeader struct {
21-
Title string
22-
Keywords string
23-
Description string
21+
Title string
22+
Keywords string
23+
Description string
2424
}
2525

2626
func GetSiteHeader(moduleName string) SiteHeader {
2727
var header SiteHeader
2828
path := "site." + moduleName + ".head"
2929
err := viper.UnmarshalKey(path, &header)
3030
if err != nil {
31-
panic(fmt.Errorf("Fatal error config file: %s \n", err))
31+
panic(fmt.Errorf("Fatal error config file: %s \n", err))
3232
}
3333
return header
3434
}
3535

3636
func (h *SiteHeader) SetTitle(title string) {
3737
h.Title = title + h.Title
38-
}
38+
}

server.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@ package main
22

33
import (
44
"github.com/labstack/echo"
5+
"github.com/labstack/gommon/log"
56

7+
"github.com/labstack/echo/middleware"
68
"github.com/mrlsd/echo-cms/config"
79
"github.com/mrlsd/echo-cms/modules/backend"
8-
"github.com/gpmgo/gopm/modules/log"
910
)
1011

1112
func main() {
1213
config.LoadConfig()
1314

1415
e := echo.New()
16+
17+
// Routers
18+
backend.UrlRules(e)
19+
e.Static("/", "static")
20+
1521
e.Debug = true
1622
e.Logger.SetLevel(log.DEBUG)
17-
e.Static("/", "static")
23+
e.Pre(middleware.NonWWWRedirect())
24+
e.Use(middleware.Secure())
25+
e.Use(middleware.CSRF())
26+
//e.Use(middleware.Logger())
27+
e.Use(middleware.Recover())
28+
e.Use(middleware.BodyLimit("2M"))
1829

19-
backend.UrlRules(e)
20-
e.Start(":3000")
30+
e.Logger.Fatal(e.Start(":3000"))
2131
}

0 commit comments

Comments
 (0)