@@ -3,6 +3,8 @@ package main
3
3
import (
4
4
"github.com/gin-gonic/gin"
5
5
"github.com/jitsucom/bulker/jitsubase/appbase"
6
+ "github.com/jitsucom/bulker/jitsubase/utils"
7
+
6
8
"net/http"
7
9
)
8
10
@@ -15,7 +17,7 @@ type Router struct {
15
17
func NewRouter (context * Context ) * Router {
16
18
base := appbase .NewRouterBase (context .config .Config , []string {
17
19
"/health" ,
18
- "/admin " ,
20
+ "/" ,
19
21
"/static" ,
20
22
})
21
23
router := & Router {
@@ -40,9 +42,30 @@ func NewRouter(context *Context) *Router {
40
42
reprocessingAPI .POST ("/jobs/:id/cancel" , router .cancelReprocessingJob )
41
43
42
44
// Serve HTML interface for admin (no auth required for UI, auth handled via form)
43
- engine .GET ("/admin " , router .serveAdminHTML )
45
+ engine .GET ("/" , router .serveAdminHTML )
44
46
engine .Static ("/static" , "./static" )
45
47
46
48
return router
47
49
48
50
}
51
+ func (r * Router ) CorsMiddleware (c * gin.Context ) {
52
+ origin := c .GetHeader ("Origin" )
53
+ if c .Request .Method == "OPTIONS" {
54
+ c .Header ("Access-Control-Allow-Origin" , utils .NvlString (origin , "*" ))
55
+ c .Header ("Access-Control-Allow-Methods" , "GET,POST,HEAD,OPTIONS" )
56
+ // x-jitsu-custom - in case client want to add some custom payload via header
57
+ c .Header ("Access-Control-Allow-Headers" , "x-enable-debug, x-write-key, authorization, content-type, x-ip-policy, cache-control, x-jitsu-custom" )
58
+ c .Header ("Access-Control-Allow-Credentials" , "true" )
59
+ c .Header ("Access-Control-Max-Age" , "86400" )
60
+ c .AbortWithStatus (http .StatusOK )
61
+ return
62
+ } else if origin != "" {
63
+ c .Header ("Access-Control-Allow-Origin" , origin )
64
+ c .Header ("Access-Control-Allow-Methods" , "GET,POST,HEAD,OPTIONS" )
65
+ // x-jitsu-custom - in case client want to add some custom payload via header
66
+ c .Header ("Access-Control-Allow-Headers" , "x-enable-debug, x-write-key, authorization, content-type, x-ip-policy, cache-control, x-jitsu-custom" )
67
+ c .Header ("Access-Control-Allow-Credentials" , "true" )
68
+ c .Header ("Access-Control-Max-Age" , "86400" )
69
+ }
70
+ c .Next ()
71
+ }
0 commit comments