|
@@ -13,6 +13,28 @@ import (
|
|
|
"golang.org/x/net/publicsuffix"
|
|
|
)
|
|
|
|
|
|
+var staticRoutes = [...]string{
|
|
|
+ "/siteaudit/i18n/messages_en",
|
|
|
+ "/siteaudit/index/",
|
|
|
+ "/siteaudit/review/",
|
|
|
+ "/seo-dashboard/release/",
|
|
|
+ "/competitive-list-widget/",
|
|
|
+ "/backlink-audit/landing/",
|
|
|
+ "/link-building-tool/landing/",
|
|
|
+ "/keyword-overview/",
|
|
|
+ "/keyword-gap/",
|
|
|
+ "/oti/prod/organic_traffic_insights/",
|
|
|
+ "/ajst/",
|
|
|
+ "/listing-management/landings/",
|
|
|
+ "/listing-management/landing-reviews/",
|
|
|
+ "/messaging/apps/",
|
|
|
+}
|
|
|
+
|
|
|
+var apiRoutes = [...]string{
|
|
|
+ "/projects/api/",
|
|
|
+ "/siteaudit/api/",
|
|
|
+}
|
|
|
+
|
|
|
// Implementing a 'set'
|
|
|
var NonmutableHeaders = map[string]struct{}{
|
|
|
"Cookie": struct{}{},
|
|
@@ -58,50 +80,29 @@ func NewController(cfg *HttpServerConfig) *Controller {
|
|
|
This handler will be responsible for proxying out the GET requests that the server recieves
|
|
|
*/
|
|
|
func (c *Controller) Get(ctx *gin.Context) {
|
|
|
- var allowedDomain string
|
|
|
- if ctx.Param("ProxiedPath") == "/siteaudit/i18n/messages_en.fd3cadbc.json" {
|
|
|
- data, ctype, err := c.RetrieveStaticResource(ctx.Param("ProxiedPath"))
|
|
|
- if err != nil {
|
|
|
- log.Fatal(err, "failed to get site config")
|
|
|
+ incomingPath := ctx.Param("ProxiedPath")
|
|
|
+ for idx := range staticRoutes {
|
|
|
+ if strings.Contains(incomingPath, staticRoutes[idx]) {
|
|
|
+ data, ctype, err := c.RetrieveStaticResource(incomingPath)
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal(err, "failed to get site config")
|
|
|
+ }
|
|
|
+ ctx.Data(200, ctype, data)
|
|
|
+ return
|
|
|
}
|
|
|
- ctx.Data(200, ctype, data)
|
|
|
- return
|
|
|
- }
|
|
|
- if strings.Contains(ctx.Param("ProxiedPath"), "/siteaudit/index/") {
|
|
|
- data, ctype, err := c.RetrieveStaticResource(ctx.Param("ProxiedPath"))
|
|
|
- if err != nil {
|
|
|
- log.Fatal(err, "failed to get site config")
|
|
|
- }
|
|
|
- ctx.Data(200, ctype, data)
|
|
|
- return
|
|
|
}
|
|
|
- if strings.Contains(ctx.Param("ProxiedPath"), "/siteaudit/review/") {
|
|
|
- data, ctype, err := c.RetrieveStaticResource(ctx.Param("ProxiedPath"))
|
|
|
- if err != nil {
|
|
|
- log.Fatal(err, "failed to get site config")
|
|
|
+ for idx := range apiRoutes {
|
|
|
+ if strings.Contains(incomingPath, apiRoutes[idx]) {
|
|
|
+ data, ctype, err := c.SiteauditApiCall(ctx.Request.Method, incomingPath, ctx.Request.URL.RawQuery, ctx.Request.Body)
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal(err, "failed to get site config")
|
|
|
+ }
|
|
|
+ ctx.Data(200, ctype, data)
|
|
|
+ return
|
|
|
}
|
|
|
- ctx.Data(200, ctype, data)
|
|
|
- return
|
|
|
- }
|
|
|
- if strings.Contains(ctx.Param("ProxiedPath"), "/projects/api/") {
|
|
|
- data, ctype, err := c.SiteauditApiCall(ctx.Request.Method, ctx.Param("ProxiedPath"), ctx.Request.URL.RawQuery, ctx.Request.Body)
|
|
|
- if err != nil {
|
|
|
- log.Fatal(err, "failed to get site config")
|
|
|
- }
|
|
|
- ctx.Data(200, ctype, data)
|
|
|
- return
|
|
|
- }
|
|
|
- if strings.Contains(ctx.Param("ProxiedPath"), "/siteaudit/api/") {
|
|
|
- data, ctype, err := c.SiteauditApiCall(ctx.Request.Method, ctx.Param("ProxiedPath"), ctx.Request.URL.RawQuery, ctx.Request.Body)
|
|
|
- if err != nil {
|
|
|
- log.Fatal(err, "failed to get site config")
|
|
|
- }
|
|
|
- ctx.Data(200, ctype, data)
|
|
|
- return
|
|
|
}
|
|
|
|
|
|
- allowedDomain = c.Config.AllowedDomain
|
|
|
- reqUrl := fmt.Sprintf("https://%s%s", allowedDomain, ctx.Param("ProxiedPath"))
|
|
|
+ reqUrl := fmt.Sprintf("https://%s%s", c.Config.AllowedDomain, incomingPath)
|
|
|
req, err := http.NewRequest(ctx.Request.Method, reqUrl, ctx.Request.Body)
|
|
|
if err != nil {
|
|
|
ctx.JSON(500, map[string]string{
|
|
@@ -110,15 +111,13 @@ func (c *Controller) Get(ctx *gin.Context) {
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- req.URL.Path = ctx.Param("ProxiedPath")
|
|
|
- cookie, err := ctx.Cookie("csrftoken")
|
|
|
+ req.URL.Path = incomingPath
|
|
|
req.Header.Add("User-Agent", c.Config.UserAgent)
|
|
|
- req.AddCookie(&http.Cookie{Name: "csrftoken", Value: cookie, Path: "/siteaudit", MaxAge: 3600, HttpOnly: true, Secure: true, SameSite: http.SameSiteNoneMode})
|
|
|
req.Header.Set("Referer", c.Config.AllowedDomain)
|
|
|
- if ctx.Param("ProxiedPath") == "/" {
|
|
|
+ if incomingPath == "/" {
|
|
|
ctx.Header("Location", "https://sem.bunnytools.shop/analytics/overview/")
|
|
|
}
|
|
|
- if ctx.Param("ProxiedPath") == "/_compatibility/traffic/overview/" {
|
|
|
+ if incomingPath == "/_compatibility/traffic/overview/" {
|
|
|
ctx.Header("Location", "https://sem.bunnytools.shop/analytics/traffic/overview/ebay.com")
|
|
|
}
|
|
|
for k, v := range ctx.Request.Header {
|