Skip to content

Commit

Permalink
Added X-Forwarded-Prefix header handling, so app can run behind a pre…
Browse files Browse the repository at this point in the history
…fix of a reverse proxy
  • Loading branch information
schulterklopfer committed Mar 31, 2019
1 parent 5d174f0 commit 130f8ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ type InstallationInfoContainer struct {
Active bool `json:"active"`
}

type InstallationInfo struct {
type TemplateData struct {
Features []InstallationInfoFeature `json:"features"`
Containers []InstallationInfoContainer `json:"containers"`
ForwardedPrefix string
}

var auth *cnAuth.CnAuth
Expand All @@ -73,11 +74,13 @@ var passwordHashes map[string][]byte
var httpClient *http.Client
var log = logging.MustGetLogger("main")

func RootHandler(w http.ResponseWriter, _ *http.Request) {

func RootHandler(w http.ResponseWriter, req *http.Request) {
installationInfo, err := getInstallatioInfo()
if err != nil {
log.Errorf("Error retrieving installation info %s", err )
}
installationInfo.ForwardedPrefix = req.Header.Get("X-Forwarded-Prefix")
rootTemplate.Execute(w, installationInfo)
}

Expand Down Expand Up @@ -118,7 +121,7 @@ func getBodyUsingAuth( url string ) ([]byte,error) {
return body, nil
}

func getInstallatioInfo() (*InstallationInfo,error) {
func getInstallatioInfo() (*TemplateData,error) {
log.Info("getInstallatioInfo")
body,err := getBodyUsingAuth( installationInfoUrl )

Expand All @@ -130,7 +133,7 @@ func getInstallatioInfo() (*InstallationInfo,error) {
log.Infof("getInstallatioInfo: %", string(body))


installationInfo := new( InstallationInfo )
installationInfo := new(TemplateData)

err = json.Unmarshal( body, &installationInfo )

Expand Down
1 change: 0 additions & 1 deletion static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
margin-bottom: 0px;
height: 100%;
widows: 100%;
background-image: url("/static/images/cyphernode_bitcoin-22x.png");
background-size: contain;
background-position: center;
background-repeat: no-repeat;
Expand Down
13 changes: 8 additions & 5 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<html lang="en">

<head>
{{if .ForwardedPrefix }}
<base href="{{.ForwardedPrefix}}/"/>
{{end}}
<title>Cyphernode info page</title>
<link rel="stylesheet" href="static/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="static/css/main.css" rel="stylesheet">
Expand Down Expand Up @@ -33,7 +36,7 @@
<!-- Full Page Image Header with Vertically Centered Content -->
<header class="masthead">
<div class="container h-100">
<div class="logo"></div>
<div class="logo" style="background-image: url(static/images/cyphernode_bitcoin-22x.png);"></div>
</div>
</header>

Expand All @@ -56,14 +59,14 @@
<a name="files"></a><h3 class="font-weight-light">Files:</h3>
<div>The following files have been encrypted with your configuration passphrase and your client keys passphrase, respectively:</div>
<ul>
<li><a href="/config.7z">Download your Cyphernode <b>configurations</b>, can be used for another Cyphernode deployment</a></li>
<li><a href="/certs.7z">Download Client <b>API ID's and keys</b>, needed in your client apps</a></li>
<li><a href="config.7z">Download your Cyphernode <b>configurations</b>, can be used for another Cyphernode deployment</a></li>
<li><a href="certs.7z">Download Client <b>API ID's and keys</b>, needed in your client apps</a></li>
</ul>
</div>
</section>

<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/verificationProgress.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/verificationProgress.js"></script>

<section class="py-2">
<div class="container">
Expand Down

0 comments on commit 130f8ef

Please sign in to comment.