Merge pull request #10 from mellodoot/dev

fix address logging and display url
This commit is contained in:
ari melody 2024-01-19 04:31:27 +00:00 committed by GitHub
commit c69d0bd891
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 5 deletions

View file

@ -91,7 +91,7 @@ to help you feel a little more comfortable, i've prepared some commands for you:
* closes any existing websocket connection and attempts to create a new one.
* @param {string} server_url - the server websocket url to connect to.
*/
export async function connect(server_url) {
export async function connect(url) {
if (client && client.readyState == 1) { // OPEN
client.close();
@ -140,9 +140,18 @@ export async function connect(server_url) {
*/
function add_client_events(client) {
client.addEventListener('open', async () => {
console.log(`Successfully connected to ${client.url}.`);
server_url = client.url;
console.log(`Successfully connected to ${server_url}.`);
server_indicator.innerText = function() {
if (client.url.startsWith("ws://"))
return client.url.slice(5, -1);
else if (client.url.startsWith("wss://"))
return client.url.slice(6, -1);
else
return client.url;
}();
server_indicator.innerText = server_url;
add_system_message(`Connection successful.\n\n`);
add_system_message(`=== BEGIN SESSION ===\n\n`);

View file

@ -130,10 +130,10 @@ function log_request(req, res, time) {
}
function get_real_address(req) {
if (TRUSTED_PROXIES.indexOf(req.socket.localAddress) !== -1 && req.headers['x-forwarded-for']) {
if (TRUSTED_PROXIES.indexOf(req.connection.remoteAddress) !== -1 && req.headers['x-forwarded-for']) {
return req.headers['x-forwarded-for'];
}
return req.socket.localAddress;
return req.connection.remoteAddress;
}
const wss = new Websocket.Server({ server });