Skip to content

Commit 8cc3992

Browse files
committed
Don't ip address lookup local addresses and remove optional end slash
1 parent be8dd0f commit 8cc3992

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

api/likes.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import axios from 'axios'
33
import faunadb, { query as q } from 'faunadb'
44

55
const getLocationData = async ipAddress => {
6-
if (ipAddress) {
6+
if (ipAddress && ipAddress !== '::1') {
7+
console.log('ipAddress: ', ipAddress)
78
const response = await axios.get(`https://ipapi.co/${ipAddress}/json/`)
89
const {
910
data: { city, region, country },
@@ -31,10 +32,11 @@ module.exports = async (req, res) => {
3132
.json({ error: new Error('Missing secret to connect to FaunaDB') })
3233
}
3334

34-
const { host, pathname } = url.parse(req.headers.referer)
35+
let { host, pathname } = url.parse(req.headers.referer)
3536

3637
console.log('host: ', host)
3738
console.log('pathname: ', pathname)
39+
pathname = pathname.replace(/\/$/g, '')
3840

3941
switch (req.method) {
4042
case 'GET':

api/messages.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import axios from 'axios'
33
import faunadb, { query as q } from 'faunadb'
44

55
const getLocationData = async ipAddress => {
6-
if (ipAddress) {
6+
if (ipAddress && ipAddress !== '::1') {
77
const response = await axios.get(`https://ipapi.co/${ipAddress}/json/`)
88
const {
99
data: { city, region, country },

0 commit comments

Comments
 (0)