merge wsurl with url

pull/5613/head
PoleTransformer 2025-02-24 16:06:53 -08:00
parent 5bca760d58
commit 2ad0d7805a
6 changed files with 12 additions and 24 deletions

View File

@ -1,15 +1,13 @@
// Add websocket URL
// Add websocket ignore headers
exports.up = function (knex) {
return knex.schema
.alterTable("monitor", function (table) {
table.text("wsurl");
table.boolean("ws_ignore_headers").notNullable().defaultTo(false);
});
};
exports.down = function (knex) {
return knex.schema.alterTable("monitor", function (table) {
table.dropColumn("wsurl");
table.dropColumn("ws_ignore_headers");
});
};

View File

@ -96,7 +96,6 @@ class Monitor extends BeanModel {
parent: this.parent,
childrenIDs: preloadData.childrenIDs.get(this.id) || [],
url: this.url,
wsurl: this.wsurl,
wsIgnoreHeaders: this.getWsIgnoreHeaders(),
method: this.method,
hostname: this.hostname,

View File

@ -21,7 +21,7 @@ class WebSocketMonitorType extends MonitorType {
*/
async attemptUpgrade(monitor) {
return new Promise((resolve) => {
const ws = new WebSocket(monitor.wsurl);
const ws = new WebSocket(monitor.url);
ws.addEventListener("open", (event) => {
// Immediately close the connection

View File

@ -790,7 +790,6 @@ let needSetup = false;
bean.parent = monitor.parent;
bean.type = monitor.type;
bean.url = monitor.url;
bean.wsurl = monitor.wsurl;
bean.wsIgnoreHeaders = monitor.wsIgnoreHeaders;
bean.method = monitor.method;
bean.body = monitor.body;

View File

@ -117,15 +117,9 @@
</div>
<!-- URL -->
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'real-browser' " class="my-3">
<div v-if="monitor.type === 'websocket-upgrade' || monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'real-browser' " class="my-3">
<label for="url" class="form-label">{{ $t("URL") }}</label>
<input id="url" v-model="monitor.url" type="url" class="form-control" pattern="https?://.+" required data-testid="url-input">
</div>
<!-- Websocket -->
<div v-if="monitor.type === 'websocket-upgrade'" class="my-3">
<label for="wsurl" class="form-label">{{ $t("URL") }}</label>
<input id="wsurl" v-model="monitor.wsurl" type="wsurl" class="form-control" pattern="wss?://.+" required data-testid="url-input">
<input id="url" v-model="monitor.url" type="url" class="form-control" :pattern="monitor.type !== 'websocket-upgrade' ? 'https?://.+' : 'wss?://.+'" required data-testid="url-input">
</div>
<!-- gRPC URL -->
@ -1094,7 +1088,6 @@ const monitorDefaults = {
name: "",
parent: null,
url: "https://",
wsurl: "wss://",
wsIgnoreHeaders: false,
method: "GET",
interval: 60,
@ -1444,6 +1437,9 @@ message HealthCheckResponse {
},
"monitor.type"(newType, oldType) {
if (oldType && this.monitor.type === "websocket-upgrade") {
this.monitor.url = "wss://";
}
if (this.monitor.type === "push") {
if (! this.monitor.pushToken) {
// ideally this would require checking if the generated token is already used
@ -1749,10 +1745,6 @@ message HealthCheckResponse {
this.monitor.url = this.monitor.url.trim();
}
if (this.monitor.wsurl) {
this.monitor.wsurl = this.monitor.wsurl.trim();
}
let createdNewParent = false;
if (this.draftGroupName && this.monitor.parent === -1) {

View File

@ -10,7 +10,7 @@ describe("Websocket Test", {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
wsurl: "wss://example.org",
url: "wss://example.org",
wsIgnoreHeaders: false,
};
@ -32,7 +32,7 @@ describe("Websocket Test", {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
wsurl: "wss://echo.websocket.org",
url: "wss://echo.websocket.org",
wsIgnoreHeaders: false,
};
@ -56,7 +56,7 @@ describe("Websocket Test", {
const wss = new WebSocketServer({ port: 8080 });
const monitor = {
wsurl: "ws://localhost:8080",
url: "ws://localhost:8080",
wsIgnoreHeaders: false,
};
@ -78,7 +78,7 @@ describe("Websocket Test", {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
wsurl: "wss://c.img-cdn.net/yE4s7KehTFyj/",
url: "wss://c.img-cdn.net/yE4s7KehTFyj/",
wsIgnoreHeaders: false,
};
@ -100,7 +100,7 @@ describe("Websocket Test", {
const websocketMonitor = new WebSocketMonitorType();
const monitor = {
wsurl: "wss://c.img-cdn.net/yE4s7KehTFyj/",
url: "wss://c.img-cdn.net/yE4s7KehTFyj/",
wsIgnoreHeaders: true,
};