mirror of
https://github.com/hanzoai/frappe.git
synced 2026-11-09 14:28:40 +00:00
* fix(socketio): short circuit websocket if in frappe cloud * fix(socketio): validate host using `get_site_name` * fix(socketio): handle redirects * fix(socketio): redirect should match `fetch` behavior * fix(socketio): add error handler on request * fix(socketio): reuse reuse parsed host in case of redirect * fix(socket): use `redirect.host` instead of `hostname` * fix(realtime): route auth over loopback with X-Frappe-Site-Name to bypass CDN * fix(realtime): make web-process host configurable via webserver_host, default to origin * fix(realtime): normalize webserver_host scheme and port in auth URL builder * fix(realtime): Fix the port after slash issue Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * fix(realtime): Fix the port after slash issue Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: Tanmoy Sarkar <[email protected]> Co-authored-by: Tanmoy Sarkar <[email protected]> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
40 lines
853 B
JavaScript
40 lines
853 B
JavaScript
const { get_conf } = require("../node_utils");
|
|
const conf = get_conf();
|
|
|
|
function get_hostname(url) {
|
|
if (!url) return undefined;
|
|
if (url.indexOf("://") > -1) {
|
|
url = url.split("/")[2];
|
|
}
|
|
return url.match(/:/g) ? url.slice(0, url.indexOf(":")) : url;
|
|
}
|
|
|
|
function get_url(socket, path) {
|
|
if (!path) {
|
|
path = "";
|
|
}
|
|
if (conf.webserver_host && conf.webserver_port) {
|
|
let base = conf.webserver_host;
|
|
if (base.indexOf("://") === -1) {
|
|
base = `http://${base}`;
|
|
}
|
|
const url = new URL(base);
|
|
if (!url.port) {
|
|
url.port = conf.webserver_port;
|
|
}
|
|
return url.origin + path;
|
|
}
|
|
let url = socket.request.headers.origin;
|
|
if (conf.developer_mode) {
|
|
let [protocol, host, port] = url.split(":");
|
|
port = conf.webserver_port;
|
|
url = `${protocol}:${host}:${port}`;
|
|
}
|
|
return url + path;
|
|
}
|
|
|
|
module.exports = {
|
|
get_hostname,
|
|
get_url,
|
|
};
|