-
-
Notifications
You must be signed in to change notification settings - Fork 211
/
backend_middleware.go
42 lines (39 loc) · 939 Bytes
/
backend_middleware.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
package backend
import (
"github.com/admpub/nging/v3/application/handler"
"github.com/webx-top/echo"
"github.com/webx-top/echo/subdomains"
)
func BackendURLFuncMW() echo.MiddlewareFunc {
return func(h echo.Handler) echo.Handler {
return echo.HandlerFunc(func(c echo.Context) error {
BackendURLFunc(c)
return h.Handle(c)
})
}
}
func BackendURLFunc(c echo.Context) error {
c.SetFunc(`AssetsURL`, func(paths ...string) (r string) {
r = AssetsURLPath
for _, ppath := range paths {
r += ppath
}
return r
})
c.SetFunc(`BackendURL`, func(paths ...string) (r string) {
r = handler.BackendPrefix
for _, ppath := range paths {
r += ppath
}
return r
//return subdomains.Default.URL(r, `backend`)
})
c.SetFunc(`FrontendURL`, func(paths ...string) (r string) {
r = handler.FrontendPrefix
for _, ppath := range paths {
r += ppath
}
return subdomains.Default.URL(r, `frontend`)
})
return nil
}