Browse Source

Added support for url prefixes when behind a web server sub path (see server.conf.in basePath configuration).

pull/3/head
Simon Eisenmann 12 years ago
parent
commit
8dabd2cfd0
  1. 2
      html/head.html
  2. 1
      server.conf.in
  3. 5
      src/app/spreed-speakfreely-server/config.go
  4. 22
      src/app/spreed-speakfreely-server/main.go
  5. 2
      static/js/services/mediastream.js

2
html/head.html

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<base href="/">
<base href="<%.Cfg.B%>">
<link rel="stylesheet" type="text/css" href="<%.Cfg.S%>/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%.Cfg.S%>/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="<%.Cfg.S%>/css/main.min.css">

1
server.conf.in

@ -5,6 +5,7 @@ listen = 127.0.0.1:8080 @@ -5,6 +5,7 @@ listen = 127.0.0.1:8080
#root = /usr/share/spreed-speakfreely-server/www
#readtimeout = 10
#writetimeout = 10
#basePath = /some/sub/path/ # Set this when running behind a web server under a sub path.
[app]
#title = Spreed Speak Freely

5
src/app/spreed-speakfreely-server/config.go

@ -28,6 +28,7 @@ type Config struct { @@ -28,6 +28,7 @@ type Config struct {
Title string // Title
ver string // Version (not exported to Javascript)
S string // Static URL prefix with version
B string // Base URL
StunURIs []string // STUN server URIs
TurnURIs []string // TURN server URIs
Tokens bool // True when we got a tokens file
@ -36,7 +37,7 @@ type Config struct { @@ -36,7 +37,7 @@ type Config struct {
Plugin string // Plugin to load
}
func NewConfig(title, ver, runtimeVersion string, stunURIs, turnURIs []string, tokens bool, globalRoomid, plugin string) *Config {
func NewConfig(title, ver, runtimeVersion, basePath string, stunURIs, turnURIs []string, tokens bool, globalRoomid, plugin string) *Config {
sv := fmt.Sprintf("static/ver=%s", ver)
return &Config{Title: title, ver: ver, S: sv, StunURIs: stunURIs, TurnURIs: turnURIs, Tokens: tokens, Version: runtimeVersion, globalRoomid: globalRoomid, Plugin: plugin}
return &Config{Title: title, ver: ver, S: sv, B: basePath, StunURIs: stunURIs, TurnURIs: turnURIs, Tokens: tokens, Version: runtimeVersion, globalRoomid: globalRoomid, Plugin: plugin}
}

22
src/app/spreed-speakfreely-server/main.go

@ -143,6 +143,17 @@ func runner(runtime phoenix.Runtime) error { @@ -143,6 +143,17 @@ func runner(runtime phoenix.Runtime) error {
return fmt.Errorf("Unable to find client. Path correct and compiled css?")
}
// Read base path from config and make sure it ends with a slash.
basePath, err := runtime.GetString("http", "basePath")
if err != nil {
basePath = "/"
} else {
if !strings.HasSuffix(basePath, "/") {
basePath = fmt.Sprintf("%s/", basePath)
}
log.Printf("Using '%s' base base path.", basePath)
}
sessionSecret, err := runtime.GetString("app", "sessionSecret")
if err != nil {
return fmt.Errorf("No sessionSecret in config file.")
@ -218,7 +229,7 @@ func runner(runtime phoenix.Runtime) error { @@ -218,7 +229,7 @@ func runner(runtime phoenix.Runtime) error {
}
// Create configuration data structure.
config = NewConfig(title, ver, runtimeVersion, stunURIs, turnURIs, tokenProvider != nil, globalRoomid, plugin)
config = NewConfig(title, ver, runtimeVersion, basePath, stunURIs, turnURIs, tokenProvider != nil, globalRoomid, plugin)
// Load templates.
tt := template.New("")
@ -262,11 +273,12 @@ func runner(runtime phoenix.Runtime) error { @@ -262,11 +273,12 @@ func runner(runtime phoenix.Runtime) error {
}
// Create router.
r := mux.NewRouter()
router := mux.NewRouter()
r := router.PathPrefix(basePath).Subrouter().StrictSlash(true)
r.HandleFunc("/", httputils.MakeGzipHandler(mainHandler))
r.Handle("/static/{path:.*}", httputils.FileStaticServer(http.Dir(rootFolder)))
r.Handle("/robots.txt", http.FileServer(http.Dir(path.Join(rootFolder, "static"))))
r.Handle("/favicon.ico", http.FileServer(http.Dir(path.Join(rootFolder, "static", "img"))))
r.Handle("/static/{path:.*}", http.StripPrefix(basePath, httputils.FileStaticServer(http.Dir(rootFolder))))
r.Handle("/robots.txt", http.StripPrefix(basePath, http.FileServer(http.Dir(path.Join(rootFolder, "static")))))
r.Handle("/favicon.ico", http.StripPrefix(basePath, http.FileServer(http.Dir(path.Join(rootFolder, "static", "img")))))
r.Handle("/ws", makeWsHubHandler(hub))
r.HandleFunc("/{room}", httputils.MakeGzipHandler(roomHandler))
makeApiHandler(r, tokenProvider)

2
static/js/services/mediastream.js

@ -32,7 +32,7 @@ define([ @@ -32,7 +32,7 @@ define([
var globalcontext = $("#globalcontext").text();
var context = JSON.parse(globalcontext);
var url = (context.Ssl ? "wss" : "ws") + "://" + context.Host + "/ws";
var url = (context.Ssl ? "wss" : "ws") + "://" + context.Host + (context.Cfg.B || "/") + "ws";
var version = context.Cfg.Version || "unknown";
console.log("Service version: "+version);
console.log("Ws URL: "+ url);

Loading…
Cancel
Save