mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 08:26:16 -04:00
socketio: Mimic what Express does to get client IP address
This also makes it easier for plugins to get the client IP address.
This commit is contained in:
parent
ba6bdf35be
commit
661a89355f
5 changed files with 17 additions and 35 deletions
|
@ -1,4 +1,5 @@
|
|||
const express = require("../express");
|
||||
const proxyaddr = require('proxy-addr');
|
||||
var settings = require('../../utils/Settings');
|
||||
var socketio = require('socket.io');
|
||||
var socketIORouter = require("../../handler/SocketIORouter");
|
||||
|
@ -38,6 +39,14 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
|||
|
||||
io.use((socket, next) => {
|
||||
const req = socket.request;
|
||||
// Express sets req.ip but socket.io does not. Replicate Express's behavior here.
|
||||
if (req.ip == null) {
|
||||
if (settings.trustProxy) {
|
||||
req.ip = proxyaddr(req, args.app.get('trust proxy fn'));
|
||||
} else {
|
||||
req.ip = socket.handshake.address;
|
||||
}
|
||||
}
|
||||
if (!req.headers.cookie) {
|
||||
// socketio.js-client on node.js doesn't support cookies (see https://git.io/JU8u9), so the
|
||||
// token and express_sid cookies have to be passed via a query parameter for unit tests.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue