-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
45 lines (33 loc) · 1.03 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"net/http"
adrianMiddleware "github.com/dana-ross/adrian/middleware"
adrianConfig "github.com/dana-ross/adrian/config"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
// Instantiate returns a pre-configured Echo instance
func Instantiate(config adrianConfig.Config) *echo.Echo {
e := echo.New()
e.HideBanner = true
e.HidePort = true
e.Pre(middleware.AddTrailingSlash())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: config.Global.AllowedOrigins,
AllowHeaders: []string{echo.HeaderOrigin},
AllowMethods: []string{http.MethodGet},
}))
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 5,
}))
e.Use(adrianMiddleware.SetServerHeader)
e.Use(adrianMiddleware.SetCacheControlHeaders(config))
e.Use(readFromCache)
return e
}
// return404 sends an appropriate message back to the browser on a 404
func return404(c echo.Context) error {
status := make(map[string]string)
status["message"] = "Not Found"
return c.JSON(http.StatusNotFound, status)
}