Skip to content

Commit 35e3e60

Browse files
committed
Add FERRET_LISTEN_PATHPREFIX
1 parent 750cca4 commit 35e3e60

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ export FERRET_SEARCH_TIMEOUT=5000ms
147147
# HTTP address for the UI and the REST API
148148
# Default is :3030
149149
export FERRET_LISTEN_ADDRESS=:3030
150+
# A URL path prefix for the UI
151+
FERRET_LISTEN_PATHPREFIX=
150152
# A comma separated list of providers
151153
# Default value is automatically determined from the ENV variables
152154
export FERRET_LISTEN_PROVIDERS=

api/api.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ var (
2727

2828
// Options represents options
2929
type Options struct {
30-
listenAddr string
31-
providersList string
30+
listenAddr string
31+
listenPathPrefix string
32+
providersList string
3233
}
3334

3435
// httpError represents an HTTP error
@@ -53,6 +54,9 @@ func init() {
5354
if e := os.Getenv("FERRET_LISTEN_ADDRESS"); e != "" {
5455
options.listenAddr = e
5556
}
57+
if e := os.Getenv("FERRET_LISTEN_PATHPREFIX"); e != "" {
58+
options.listenPathPrefix = e
59+
}
5660
if e := os.Getenv("FERRET_LISTEN_PROVIDERS"); e != "" {
5761
options.providersList = e
5862
}
@@ -77,9 +81,10 @@ func init() {
7781
// Listen initializes HTTP handlers and listens for the requests
7882
func Listen() {
7983
// Init handlers
80-
http.Handle("/", assets.PublicHandler())
81-
http.HandleFunc("/search", SearchHandler)
82-
http.HandleFunc("/providers", ProvidersHandler)
84+
lpp := strings.TrimRight(options.listenPathPrefix, "/")
85+
http.Handle("/", http.StripPrefix(options.listenPathPrefix, assets.PublicHandler()))
86+
http.HandleFunc(fmt.Sprintf("%s/search", lpp), SearchHandler)
87+
http.HandleFunc(fmt.Sprintf("%s/providers", lpp), ProvidersHandler)
8388

8489
// Listen
8590
log.Printf("listening on %s", options.listenAddr)

assets/public/js/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var app = function app() {
1818
// Init vars
1919
var serverUrl = location.protocol + '//' + location.hostname + ':' + location.port;
2020
serverUrl = (location.protocol == 'file:') ? 'http://localhost:3030' : serverUrl; // for debug
21+
var appPath = location.pathname || '/';
2122

2223
// init initializes the app
2324
function init() {
@@ -99,7 +100,7 @@ var app = function app() {
99100
// getProviders gets the provider list
100101
function getProviders() {
101102
return $.ajax({
102-
url: serverUrl+'/providers',
103+
url: serverUrl+appPath+'providers',
103104
dataType: 'jsonp',
104105
method: 'GET',
105106
}).promise();
@@ -108,7 +109,7 @@ var app = function app() {
108109
// search makes a search by the given provider and keyword
109110
function search(provider, keyword) {
110111
return $.ajax({
111-
url: serverUrl+'/search',
112+
url: serverUrl+appPath+'search',
112113
dataType: 'jsonp',
113114
method: 'GET',
114115
data: {

0 commit comments

Comments
 (0)