diff --git a/src/newWeb/server.go b/src/newWeb/server.go new file mode 100644 index 0000000..dc2dffc --- /dev/null +++ b/src/newWeb/server.go @@ -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()) + } +} diff --git a/src/server.go b/src/server.go index f275b49..f9c431e 100644 --- a/src/server.go +++ b/src/server.go @@ -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" @@ -28,6 +29,7 @@ func init() { func main() { hosts := map[string]*echo.Echo{ "": web.Server(), + "new": newWeb.Server(), "files": s3proxy.Server(), "api": api.Server(), }