Skip to content

Commit

Permalink
adds config option for setting the app's base url (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoah committed Feb 7, 2021
1 parent e37a9a0 commit 86f07d7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Server struct {

StoragePath string `def:"<installPrefix>/var/lib/pyroscope" desc:"directory where pyroscope stores profiling data"`
ApiBindAddr string `def:":4040" desc:"port for the HTTP server used for data ingestion and web UI"`
BaseURL string `def:"" desc:"base URL for when the server is behind a reverse proxy with a different path"`

// These will eventually be replaced by some sort of a system that keeps track of RAM
// and updates
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type indexPage struct {
InitialState string
BuildInfo string
ExtraMetadata string
BaseURL string
}

func (ctrl *Controller) renderIndexPage(dir http.FileSystem, rw http.ResponseWriter, _ *http.Request) {
Expand Down Expand Up @@ -185,6 +186,7 @@ func (ctrl *Controller) renderIndexPage(dir http.FileSystem, rw http.ResponseWri
InitialState: initialStateStr,
BuildInfo: buildInfoStr,
ExtraMetadata: extraMetadataStr,
BaseURL: ctrl.cfg.Server.BaseURL,
})
if err != nil {
renderServerError(rw, fmt.Sprintf("could not marshal json: %q", err))
Expand Down
2 changes: 1 addition & 1 deletion webapp/javascript/util/update_requests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function buildRenderURL(state) {
const { from, until } = state;

let url = `/render?from=${encodeURIComponent(from)}&until=${encodeURIComponent(until)}`;
let url = `render?from=${encodeURIComponent(from)}&until=${encodeURIComponent(until)}`;
const nameLabel = state.labels.find((x) => x.name == '__name__');

if (nameLabel) {
Expand Down
3 changes: 3 additions & 0 deletions webapp/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<meta name="viewport" content="width=device-width">
<title>Pyroscope</title>
<link rel="stylesheet" href="build/styles.<%= webpack.hash %>.css">
{{- if .BaseURL }}
<base href="{{ .BaseURL }}">
{{- end }}
{{ .ExtraMetadata }}
<%= extra_metadata %>
<% if (mode == "development") { %>
Expand Down

0 comments on commit 86f07d7

Please sign in to comment.