Change static assets and websocket interface to /sshwifty/assets and /sshwifty/socket. This should allow user to map Sshwifty to a subdirectory behind a reverse proxy
This commit is contained in:
@@ -34,6 +34,11 @@ var (
|
|||||||
http.StatusNotFound, "Page not found")
|
http.StatusNotFound, "Page not found")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
assetsURLPrefix = "/sshwifty/assets/"
|
||||||
|
assetsURLPrefixLen = len(assetsURLPrefix)
|
||||||
|
)
|
||||||
|
|
||||||
// handler is the main service dispatcher
|
// handler is the main service dispatcher
|
||||||
type handler struct {
|
type handler struct {
|
||||||
hostNameChecker string
|
hostNameChecker string
|
||||||
@@ -73,14 +78,39 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
case "/":
|
case "/":
|
||||||
err = serveController(h.homeCtl, w, r, clientLogger)
|
err = serveController(h.homeCtl, w, r, clientLogger)
|
||||||
|
|
||||||
case "/socket":
|
case "/sshwifty/socket":
|
||||||
err = serveController(h.socketCtl, w, r, clientLogger)
|
err = serveController(h.socketCtl, w, r, clientLogger)
|
||||||
|
|
||||||
|
case "/robots.txt":
|
||||||
|
err = serveStaticCacheData(
|
||||||
|
"robots.txt",
|
||||||
|
staticFileExt(".txt"),
|
||||||
|
w,
|
||||||
|
r,
|
||||||
|
clientLogger)
|
||||||
|
|
||||||
|
case "/favicon.ico":
|
||||||
|
err = serveStaticCacheData(
|
||||||
|
"favicon.ico",
|
||||||
|
staticFileExt(".ico"),
|
||||||
|
w,
|
||||||
|
r,
|
||||||
|
clientLogger)
|
||||||
|
|
||||||
|
case "/manifest.json":
|
||||||
|
err = serveStaticCacheData(
|
||||||
|
"manifest.json",
|
||||||
|
staticFileExt(".json"),
|
||||||
|
w,
|
||||||
|
r,
|
||||||
|
clientLogger)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if len(r.URL.Path) > 0 && strings.ToUpper(r.Method) == "GET" {
|
if strings.HasPrefix(r.URL.Path, assetsURLPrefix) &&
|
||||||
|
strings.ToUpper(r.Method) == "GET" {
|
||||||
err = serveStaticCacheData(
|
err = serveStaticCacheData(
|
||||||
r.URL.Path[1:],
|
r.URL.Path[assetsURLPrefixLen:],
|
||||||
staticFileExt(r.URL.Path[1:]),
|
staticFileExt(r.URL.Path[assetsURLPrefixLen:]),
|
||||||
w,
|
w,
|
||||||
r,
|
r,
|
||||||
clientLogger)
|
clientLogger)
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ const mainTemplate = `
|
|||||||
<loading v-else :error="loadErr"></loading>
|
<loading v-else :error="loadErr"></loading>
|
||||||
`.trim();
|
`.trim();
|
||||||
|
|
||||||
|
const socksInterface = "/sshwifty/socket";
|
||||||
|
|
||||||
function startApp(rootEl) {
|
function startApp(rootEl) {
|
||||||
const pageTitle = document.title;
|
const pageTitle = document.title;
|
||||||
|
|
||||||
@@ -149,7 +151,7 @@ function startApp(rootEl) {
|
|||||||
r = "ws://";
|
r = "ws://";
|
||||||
}
|
}
|
||||||
|
|
||||||
r += location.host + "/socket";
|
r += location.host + socksInterface;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
},
|
},
|
||||||
@@ -249,7 +251,7 @@ function startApp(rootEl) {
|
|||||||
? null
|
? null
|
||||||
: await this.getSocketAuthKey(privateKey, this.key);
|
: await this.getSocketAuthKey(privateKey, this.key);
|
||||||
|
|
||||||
let h = await xhr.head("/socket", {
|
let h = await xhr.head(socksInterface, {
|
||||||
"X-Key": authKey ? btoa(String.fromCharCode.apply(null, authKey)) : ""
|
"X-Key": authKey ? btoa(String.fromCharCode.apply(null, authKey)) : ""
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ module.exports = {
|
|||||||
devtool:
|
devtool:
|
||||||
process.env.NODE_ENV === "development" ? "inline-source-map" : "source-map",
|
process.env.NODE_ENV === "development" ? "inline-source-map" : "source-map",
|
||||||
output: {
|
output: {
|
||||||
publicPath: "/",
|
publicPath: "/sshwifty/assets/",
|
||||||
path: path.join(__dirname, ".tmp", "dist"),
|
path: path.join(__dirname, ".tmp", "dist"),
|
||||||
filename: process.env.NODE_ENV === "development" ? "[id].js" : "[hash].js"
|
filename: process.env.NODE_ENV === "development" ? "[id].js" : "[hash].js"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user