Skip to content

Commit

Permalink
proxy new subdomain to 2.0 website
Browse files Browse the repository at this point in the history
proxy `new.*` to ImpactDevelopment/Website hosted on heroku
  • Loading branch information
LeafHacker committed Dec 27, 2019
1 parent 7fe80c4 commit bce6c8e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/newWeb/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package newWeb

import (
"github.com/ImpactDevelopment/ImpactServer/src/util"
"net/http"
"net/url"

mid "github.com/ImpactDevelopment/ImpactServer/src/middleware"
"github.com/labstack/echo"
)

func Server() (e *echo.Echo) {
e = echo.New()

e.GET("/ImpactInstaller.*", redirect(http.StatusFound, "https://impactclient.net/"), mid.NoCache())
e.Any("/*", proxy("https://impact-web.herokuapp.com/"))

return
}

func proxy(address string) func(echo.Context) error {
return func(c echo.Context) error {
addr := c.Request().URL

// Pull the bits we need from the heroku addr
newAddr, err := url.Parse(address)
if err != nil {
return err
}
addr.Scheme = newAddr.Scheme
addr.Host = newAddr.Host

// Proxy to heroku
util.Proxy(c, addr)
return nil
}
}

func redirect(code int, address string) func(echo.Context) error {
return func(c echo.Context) error {
addr := c.Request().URL

// Pull the bits we need from the address
newAddr, err := url.Parse(address)
if err != nil {
return err
}
addr.Scheme = newAddr.Scheme
addr.Host = newAddr.Host

// 302 to the current location
return c.Redirect(code, addr.String())
}
}
2 changes: 2 additions & 0 deletions src/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ImpactDevelopment/ImpactServer/src/cloudflare"
mid "github.com/ImpactDevelopment/ImpactServer/src/middleware"
"github.com/ImpactDevelopment/ImpactServer/src/newWeb"
"github.com/ImpactDevelopment/ImpactServer/src/s3proxy"
"github.com/ImpactDevelopment/ImpactServer/src/util"
"github.com/ImpactDevelopment/ImpactServer/src/web"
Expand All @@ -28,6 +29,7 @@ func init() {
func main() {
hosts := map[string]*echo.Echo{
"": web.Server(),
"new": newWeb.Server(),
"files": s3proxy.Server(),
"api": api.Server(),
}
Expand Down

0 comments on commit bce6c8e

Please sign in to comment.