-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proxy `new.*` to ImpactDevelopment/Website hosted on heroku
- Loading branch information
1 parent
7fe80c4
commit bce6c8e
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters