-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharcgis.go
72 lines (55 loc) · 2.22 KB
/
arcgis.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package arcGIS
import (
"github.com/gofiber/fiber/v2"
"github.com/lambda-platform/arcGIS/handlers"
"github.com/lambda-platform/arcGIS/middleware"
"github.com/lambda-platform/arcGIS/utils"
"github.com/lambda-platform/lambda/agent/agentMW"
"github.com/lambda-platform/lambda/config"
"github.com/lambda-platform/lambda/dataform"
"github.com/lambda-platform/lambda/datagrid"
"github.com/valyala/fasthttp"
"github.com/valyala/fasthttp/fasthttpadaptor"
"net/http"
"net/http/httputil"
"net/url"
)
func Set(e *fiber.App, GetGridMODEL func(schema_id string) datagrid.Datagrid, GetMODEL func(schema_id string) dataform.Dataform) {
if config.Config.App.Migrate == "true" {
utils.AutoMigrateSeed()
}
g := e.Group("/gis")
g.Get("/fill", func(c *fiber.Ctx) error {
return handlers.FillArcGISData(c, GetGridMODEL, GetMODEL)
})
g.Get("/token", agentMW.IsLoggedIn(), handlers.Token)
g.Post("/form-fields", handlers.FormFields)
target, _ := url.Parse("http://localhost:6080")
// Create a reverse proxy
proxy := httputil.NewSingleHostReverseProxy(target)
e.Use("/arcgis", func(c *fiber.Ctx) error {
// Create a new request based on the original
origin := c.Get("Origin")
req := fasthttp.Request{}
url := c.Request().URI()
url.SetScheme(target.Scheme)
url.SetHost(target.Host)
req.SetRequestURI(url.String())
req.Header.SetHost(target.Host)
fasthttpadaptor.NewFastHTTPHandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, X-Requested-With, x-csrf-token, Accept-Language, Content-Length, Authorization, Accept-Encoding, Connection")
writer.Header().Set("Access-Control-Allow-Methods", "GET,POST,HEAD,PUT,DELETE,PATCH,OPTIONS")
if writer.Header().Get("Access-Control-Allow-Origin") == "" {
writer.Header().Set("Access-Control-Allow-Origin", origin)
}
proxy.ServeHTTP(writer, request)
})(c.Context())
// Since we're writing directly to the ResponseWriter, return nil
return nil
})
}
func MW(GetGridMODEL func(schema_id string) datagrid.Datagrid, GetMODEL func(schema_id string) dataform.Dataform) fiber.Handler {
return func(c *fiber.Ctx) error {
return middleware.BodyDump(c, GetGridMODEL, GetMODEL)
}
}