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

mozilla / blurts-server / #12980

pending completion
#12980

push

circleci

Vinnl
Add redundant social media preview tags

Not all social media websites implement the same (or any) fallbacks
for preview cards, so we have to add them redundantly to make sure
they show up everywhere.

282 of 1595 branches covered (17.68%)

Branch coverage included in aggregate %.

959 of 4308 relevant lines covered (22.26%)

1.85 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