feat(ui): separate the namespace from the server URL
This should help prevent people from connecting to the main namespace, when they forget to include the namespace at the end of the server URL. Related: - https://github.com/socketio/socket.io-admin-ui/issues/26 - https://github.com/socketio/socket.io-admin-ui/issues/42
This commit is contained in:
parent
8542601b55
commit
5a8a75edc0
|
|
@ -17,6 +17,7 @@
|
||||||
:initial-server-url="serverUrl"
|
:initial-server-url="serverUrl"
|
||||||
:initial-ws-only="wsOnly"
|
:initial-ws-only="wsOnly"
|
||||||
:initial-path="path"
|
:initial-path="path"
|
||||||
|
:initial-namespace="namespace"
|
||||||
:initial-parser="parser"
|
:initial-parser="parser"
|
||||||
:is-connecting="isConnecting"
|
:is-connecting="isConnecting"
|
||||||
:error="connectionError"
|
:error="connectionError"
|
||||||
|
|
@ -70,6 +71,7 @@ export default {
|
||||||
serverUrl: (state) => state.connection.serverUrl,
|
serverUrl: (state) => state.connection.serverUrl,
|
||||||
wsOnly: (state) => state.connection.wsOnly,
|
wsOnly: (state) => state.connection.wsOnly,
|
||||||
path: (state) => state.connection.path,
|
path: (state) => state.connection.path,
|
||||||
|
namespace: (state) => state.connection.namespace,
|
||||||
parser: (state) => state.connection.parser,
|
parser: (state) => state.connection.parser,
|
||||||
backgroundColor: (state) =>
|
backgroundColor: (state) =>
|
||||||
state.config.darkTheme ? "" : "grey lighten-5",
|
state.config.darkTheme ? "" : "grey lighten-5",
|
||||||
|
|
@ -92,7 +94,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
tryConnect(serverUrl, auth, wsOnly, path, parser) {
|
tryConnect(serverUrl, namespace, auth, wsOnly, path, parser) {
|
||||||
this.isConnecting = true;
|
this.isConnecting = true;
|
||||||
if (SocketHolder.socket) {
|
if (SocketHolder.socket) {
|
||||||
SocketHolder.socket.disconnect();
|
SocketHolder.socket.disconnect();
|
||||||
|
|
@ -100,7 +102,7 @@ export default {
|
||||||
SocketHolder.socket.off("connect_error");
|
SocketHolder.socket.off("connect_error");
|
||||||
SocketHolder.socket.off("disconnect");
|
SocketHolder.socket.off("disconnect");
|
||||||
}
|
}
|
||||||
const socket = io(serverUrl, {
|
const socket = io(serverUrl + namespace, {
|
||||||
forceNew: true,
|
forceNew: true,
|
||||||
reconnection: false,
|
reconnection: false,
|
||||||
withCredentials: true, // needed for cookie-based sticky-sessions
|
withCredentials: true, // needed for cookie-based sticky-sessions
|
||||||
|
|
@ -119,6 +121,7 @@ export default {
|
||||||
serverUrl,
|
serverUrl,
|
||||||
wsOnly,
|
wsOnly,
|
||||||
path,
|
path,
|
||||||
|
namespace,
|
||||||
parser,
|
parser,
|
||||||
});
|
});
|
||||||
SocketHolder.socket = socket;
|
SocketHolder.socket = socket;
|
||||||
|
|
@ -210,6 +213,7 @@ export default {
|
||||||
onSubmit(form) {
|
onSubmit(form) {
|
||||||
this.tryConnect(
|
this.tryConnect(
|
||||||
form.serverUrl,
|
form.serverUrl,
|
||||||
|
form.namespace,
|
||||||
{
|
{
|
||||||
username: form.username,
|
username: form.username,
|
||||||
password: form.password,
|
password: form.password,
|
||||||
|
|
@ -231,6 +235,7 @@ export default {
|
||||||
const sessionId = this.$store.state.connection.sessionId;
|
const sessionId = this.$store.state.connection.sessionId;
|
||||||
this.tryConnect(
|
this.tryConnect(
|
||||||
this.serverUrl,
|
this.serverUrl,
|
||||||
|
this.namespace,
|
||||||
{
|
{
|
||||||
sessionId,
|
sessionId,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
<v-text-field
|
<v-text-field
|
||||||
v-model="serverUrl"
|
v-model="serverUrl"
|
||||||
:label="$t('connection.serverUrl')"
|
:label="$t('connection.serverUrl')"
|
||||||
placeholder="https://example.com/admin"
|
placeholder="https://example.com"
|
||||||
required
|
required
|
||||||
></v-text-field>
|
></v-text-field>
|
||||||
<v-text-field
|
<v-text-field
|
||||||
|
|
@ -25,13 +25,28 @@
|
||||||
type="password"
|
type="password"
|
||||||
></v-text-field>
|
></v-text-field>
|
||||||
|
|
||||||
|
<v-switch
|
||||||
|
v-model="showAdvancedOptions"
|
||||||
|
:label="$t('connection.advanced-options')"
|
||||||
|
inset
|
||||||
|
dense
|
||||||
|
/>
|
||||||
|
|
||||||
|
<v-expand-transition>
|
||||||
|
<div v-if="showAdvancedOptions">
|
||||||
<v-switch
|
<v-switch
|
||||||
v-model="wsOnly"
|
v-model="wsOnly"
|
||||||
:label="$t('connection.websocket-only')"
|
:label="$t('connection.websocket-only')"
|
||||||
inset
|
inset
|
||||||
dense
|
dense
|
||||||
|
v-show="showAdvancedOptions"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<v-text-field
|
||||||
|
v-model="namespace"
|
||||||
|
:label="$t('connection.namespace')"
|
||||||
|
></v-text-field>
|
||||||
|
|
||||||
<v-text-field
|
<v-text-field
|
||||||
v-model="path"
|
v-model="path"
|
||||||
:label="$t('connection.path')"
|
:label="$t('connection.path')"
|
||||||
|
|
@ -42,6 +57,8 @@
|
||||||
:label="$t('connection.parser')"
|
:label="$t('connection.parser')"
|
||||||
:items="parserOptions"
|
:items="parserOptions"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
</v-expand-transition>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
:loading="isConnecting"
|
:loading="isConnecting"
|
||||||
|
|
@ -69,15 +86,18 @@ export default {
|
||||||
initialServerUrl: String,
|
initialServerUrl: String,
|
||||||
initialWsOnly: Boolean,
|
initialWsOnly: Boolean,
|
||||||
initialPath: String,
|
initialPath: String,
|
||||||
|
initialNamespace: String,
|
||||||
initialParser: String,
|
initialParser: String,
|
||||||
error: String,
|
error: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
showAdvancedOptions: false,
|
||||||
serverUrl: this.initialServerUrl,
|
serverUrl: this.initialServerUrl,
|
||||||
wsOnly: this.initialWsOnly,
|
wsOnly: this.initialWsOnly,
|
||||||
path: this.initialPath,
|
path: this.initialPath,
|
||||||
|
namespace: this.initialNamespace,
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
parser: this.initialParser,
|
parser: this.initialParser,
|
||||||
|
|
@ -111,6 +131,7 @@ export default {
|
||||||
serverUrl: this.serverUrl,
|
serverUrl: this.serverUrl,
|
||||||
wsOnly: this.wsOnly,
|
wsOnly: this.wsOnly,
|
||||||
path: this.path,
|
path: this.path,
|
||||||
|
namespace: this.namespace,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
password: this.password,
|
password: this.password,
|
||||||
parser: this.parser,
|
parser: this.parser,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,9 @@
|
||||||
"path": "Path",
|
"path": "Path",
|
||||||
"parser": "Parser",
|
"parser": "Parser",
|
||||||
"default-parser": "Built-in parser",
|
"default-parser": "Built-in parser",
|
||||||
"msgpack-parser": "MessagePack parser"
|
"msgpack-parser": "MessagePack parser",
|
||||||
|
"namespace": "Admin namespace",
|
||||||
|
"advanced-options": "Advanced options"
|
||||||
},
|
},
|
||||||
"dashboard": {
|
"dashboard": {
|
||||||
"title": "Dashboard",
|
"title": "Dashboard",
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,12 @@
|
||||||
"invalid-credentials": "Identifiants invalides",
|
"invalid-credentials": "Identifiants invalides",
|
||||||
"error": "Erreur",
|
"error": "Erreur",
|
||||||
"websocket-only": "WebSocket uniquement ?",
|
"websocket-only": "WebSocket uniquement ?",
|
||||||
"path": "Chemin HTTP"
|
"path": "Chemin HTTP",
|
||||||
|
"parser": "Encodeur",
|
||||||
|
"default-parser": "Encodeur par défaut",
|
||||||
|
"msgpack-parser": "Encodeur basé sur MessagePack",
|
||||||
|
"namespace": "Espace de nom d'administration",
|
||||||
|
"advanced-options": "Options avancées"
|
||||||
},
|
},
|
||||||
"dashboard": {
|
"dashboard": {
|
||||||
"title": "Accueil",
|
"title": "Accueil",
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ export default {
|
||||||
serverUrl: "",
|
serverUrl: "",
|
||||||
wsOnly: false,
|
wsOnly: false,
|
||||||
path: "/socket.io",
|
path: "/socket.io",
|
||||||
|
namespace: "/admin",
|
||||||
parser: "default",
|
parser: "default",
|
||||||
sessionId: "",
|
sessionId: "",
|
||||||
connected: false,
|
connected: false,
|
||||||
|
|
@ -13,22 +14,30 @@ export default {
|
||||||
mutations: {
|
mutations: {
|
||||||
init(state) {
|
init(state) {
|
||||||
if (isLocalStorageAvailable) {
|
if (isLocalStorageAvailable) {
|
||||||
state.serverUrl = localStorage.getItem("server_url");
|
state.serverUrl = localStorage.getItem("server_url") || "";
|
||||||
|
if (state.serverUrl.endsWith("/admin")) {
|
||||||
|
// for backward compatibility
|
||||||
|
state.serverUrl = state.serverUrl.slice(0, -6);
|
||||||
|
} else {
|
||||||
|
state.namespace = localStorage.getItem("namespace") || "/admin";
|
||||||
|
}
|
||||||
state.wsOnly = localStorage.getItem("ws_only") === "true";
|
state.wsOnly = localStorage.getItem("ws_only") === "true";
|
||||||
state.sessionId = localStorage.getItem("session_id");
|
state.sessionId = localStorage.getItem("session_id");
|
||||||
state.path = localStorage.getItem("path") || "/socket.io";
|
state.path = localStorage.getItem("path") || "/socket.io";
|
||||||
state.parser = localStorage.getItem("parser") || "default";
|
state.parser = localStorage.getItem("parser") || "default";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveConfig(state, { serverUrl, wsOnly, path, parser }) {
|
saveConfig(state, { serverUrl, wsOnly, path, namespace, parser }) {
|
||||||
state.serverUrl = serverUrl;
|
state.serverUrl = serverUrl;
|
||||||
state.wsOnly = wsOnly;
|
state.wsOnly = wsOnly;
|
||||||
state.path = path;
|
state.path = path;
|
||||||
|
state.namespace = namespace;
|
||||||
state.parser = parser;
|
state.parser = parser;
|
||||||
if (isLocalStorageAvailable) {
|
if (isLocalStorageAvailable) {
|
||||||
localStorage.setItem("server_url", serverUrl);
|
localStorage.setItem("server_url", serverUrl);
|
||||||
localStorage.setItem("ws_only", wsOnly);
|
localStorage.setItem("ws_only", wsOnly);
|
||||||
localStorage.setItem("path", path);
|
localStorage.setItem("path", path);
|
||||||
|
localStorage.setItem("namespace", namespace);
|
||||||
localStorage.setItem("parser", parser);
|
localStorage.setItem("parser", parser);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue