• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / #12601

pending completion
#12601

push

circleci

mozilla-pontoon
Pontoon: Update French (fr) localization of Firefox Monitor Website

Co-authored-by: Théo Chevalier <theochevalier@pm.me>

282 of 1400 branches covered (20.14%)

Branch coverage included in aggregate %.

959 of 3802 relevant lines covered (25.22%)

2.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/controllers/ip-location.js
1
// IP location data includes GeoLite2 data created by MaxMind, available from https://www.maxmind.com.
2
// For testing, you can compare IPs to the corresponding json, eg: https://github.com/maxmind/MaxMind-DB/blob/main/source-data/GeoLite2-City-Test.json
3

4
'use strict'
5

6
const AppConstants = require('../app-constants')
×
7
const { readLocationData } = require('../ip-location-service')
×
8

9
async function getIpLocation (req, res) {
10
  let clientIp
11

12
  switch (AppConstants.NODE_ENV) {
×
13
    case 'dev':
14
      clientIp = req.headers['test-ip'] || '216.160.83.56' // fallback an IP that exists in limited/local GeoLite2 test DB
×
15
      break
×
16
    case 'heroku':
17
    case 'stage':
18
      clientIp = req.headers['test-ip'] || req.ip // Use "test-ip" header if available, fallback to original IP
×
19
      break
×
20
    default:
21
      clientIp = req.ip
×
22
  }
23

24
  if (clientIp === req.session.locationData?.clientIp) {
×
25
    return res.status(200).json(req.session.locationData) // return cached data
×
26
  }
27

28
  const locationData = await readLocationData(clientIp, req.supportedLocales)
×
29

30
  if (locationData) {
×
31
    req.session.locationData = Object.assign(locationData, { clientIp }) // cache new location data, adding clientIP key
×
32
    return res.status(200).json(req.session.locationData)
×
33
  }
34

35
  return res.status(200).json({ clientIp })
×
36
}
37

38
module.exports = {
×
39
  getIpLocation
40
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc