How to use the request-ip.getClientIp function in request-ip

To help you get started, we’ve selected a few request-ip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github delvedor / LightFirewall / test / example / promise.js View on Github external
const server = http.createServer((request, response) => {
  // gets the ip of the request
  let ip = requestIp.getClientIp(request)
  // this snippet closes the request to favicon.ico
  if (request.url === '/favicon.ico') return response.end()

  // here we add an attempt to the ip
  lf.addAttempt(ip)
    .then(() => {
      // here we check if the client has reached the maximum number of attempts
      // or if the client has an active timeout
      return lf.checkClient(ip)
    })
    .then((client) => {
      if (!client) {
        response.writeHead(200, {'Content-Type': 'text/plain'})
        response.end('Hello World\n')
      } else {
        response.writeHead(403, {'Content-Type': 'text/plain'})
github delvedor / LightFirewall / example / callback.js View on Github external
http.createServer((request, response) => {
  // gets the ip of the request
  let ip = requestIp.getClientIp(request)

  // this snippet closes the request to favicon.ico
  if (request.url === '/favicon.ico') {
    response.end()
    console.log('favicon requested')
    return
  }

  // here we add an attempt to the ip
  lf.addAttempt(ip, (errAdd) => {
    if (errAdd) return console.log(errAdd)
    // here we check if the client has reached the maximum number of attempts
    // or if the client has an active timeout
    lf.checkClient(ip, (errCheck, client) => {
      if (errCheck) return console.log(errCheck)
      if (!client) {
github rauchg / blog-views / lib / verify.js View on Github external
module.exports = (req) => {
  if ('development' === NODE_ENV) {
    // ignore limits during development
    return
  }

  const clientIp = requestIp.getClientIp(req)
  seen[clientIp] = seen[clientIp] || 0
  if (seen[clientIp] > 10) {
    const err = new Error('Too many views per IP')
    err.statusCode = 429
    throw err
  }
  seen[clientIp]++
}
github ropnop / serverless_toolkit / xxe_server / index.js View on Github external
const ipMiddleware = (req, res, next) => {
  let clientIp;
  if (req.header('cf-connecting-ip')){
    req.clientIp = req.header('cf-connecting-ip'); // I want to always give priority to this header
  } else {
    req.clientIp = requestIp.getClientIp(req); // if it's not there then fall back
  }
  next();
};
github Style-Validator / style-validator / app.js View on Github external
function sendClientIP(req, res, path) {

	parsedQueryString = querystring.parse(parsedURL.query);
	var variable = parsedQueryString['var'];
	var clientIp = requestIp.getClientIp(req);

	//jsonp
	res.writeHead(200, {'Content-Type': mimeTypes['js']});
	res.end('var ' + variable + ' = \'' + clientIp + '\';');

	console.log('Client IP has been sent successfully');
}
github accounts-js / accounts / packages / rest-express / src / endpoints / password / reset.ts View on Github external
export const resetPassword = (accountsServer: AccountsServer) => async (
  req: express.Request,
  res: express.Response
) => {
  try {
    const { token, newPassword } = req.body;
    const userAgent = getUserAgent(req);
    const ip = getClientIp(req);
    const password: any = accountsServer.getServices().password;
    const loginResult = await password.resetPassword(token, newPassword, { userAgent, ip });
    res.json(loginResult);
  } catch (err) {
    sendError(res, err);
  }
};
github ArkEcosystem / core / packages / core-p2p / lib / server / plugins / throttle / index.js View on Github external
async method (request, h) {
      const remoteAddress = requestIp.getClientIp(request)

      if (isWhitelist(['127.*'], remoteAddress)) {
        return h.continue
      }

      if (!bucket.has(remoteAddress)) {
        bucket.add(remoteAddress, isKnown(remoteAddress) ? 2000 : 1)
      }

      bucket.decrement(remoteAddress)

      if (bucket.remaining(remoteAddress) <= 0) {
        logger.debug(`${remoteAddress} has exceeded the maximum number of requests per minute.`)

        return Boom.tooManyRequests()
      }
github rollbar / rollbar.js / src / server / transforms.js View on Github external
function _extractIp(req) {
  var ip = req.ip;
  if (!ip) {
    ip = requestIp.getClientIp(req);
  }
  return ip;
}

request-ip

A small Node.js module to retrieve the request's IP address

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis

Popular request-ip functions