Error connecting to socket.io: Invalid origin. socketio_client.js:69

I have an issue running socket.io, even though frappe-bench-web:frappe-bench-node-socketio is running

frappe-bench-web:frappe-bench-node-socketio RUNNING pid 3785, uptime 0:31:19

Screenshot 2025-05-15 at 12.21.04 AM

please note that the erpnext is locally-hosted

in file apps/frappe/realtime/utils.js add loging url like:

function get_url(socket, path) {
	if (!path) {
		path = "";
	}
	let url = socket.request.headers.origin;
	console.log("socket.request.headers.origin: ", url);
	if (conf.developer_mode) {
		let [protocol, host, port] = url.split(":");
		port = conf.webserver_port;
		url = `${protocol}:${host}:${port}`;
	}
---->	console.log("url", url + path);
	return url + path;
}

open page /app/system-health-report and show last 3 lines in logs/node-socketio.log

/app/system-health-report
Screenshot 2025-05-15 at 11.08.40 AM

last 3 lines in logs/node-socketio.log
Realtime service listening on: 9000
Realtime service listening on: 9000
Realtime service listening on: 9000
these three lines looks old

if site in production mode - in console: bench restart.
If you add console.log("url", url + path); - in log file you can see full url of request.

the site is in production mode and console.log(“url”, url + path); is added as above but the full url is not shown in logs/node-socketio.log file.
console.log("Realtime service listening on: ", uds || port); is the line that log into this file which reside in frappe-bench/apps/frappe/realtime/index.js. any help will be so appreciated maks4a

Ok, try:

  1. replace source file: apps/frappe/realtime/utils.js:
const { get_conf } = require("../node_utils");
const conf = get_conf();

function get_url(socket, path) {
	if (!path) {
		path = "";
	}
	let url = socket.request.headers.origin;
	if (!conf.developer_mode) { // add "!"
		let [protocol, host, port] = url.split(":");
		port = conf.webserver_port;
		url = `${protocol}:${host}:${port}`;
	}
	console.log("url", url + path);
	return url + path;
}

module.exports = {
	get_url,
};
  1. in console bench restart

if web-socket not work - need show browser console

Is this OK:

here is the browser console:
Error connecting to socket.io: Invalid origin socketio_client.js:71

the issue persists, any suggestion is highly appreciated