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

mozilla / blurts-server / c4f1ca44-5406-4d63-85c3-5b07690378cf

pending completion
c4f1ca44-5406-4d63-85c3-5b07690378cf

push

circleci

GitHub
Merge pull request #2983 from mozilla/MNTOR-971-Landing-page-transitions

282 of 1679 branches covered (16.8%)

Branch coverage included in aggregate %.

37 of 37 new or added lines in 2 files covered. (100.0%)

959 of 4547 relevant lines covered (21.09%)

3.52 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