Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geo-ip update #3

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const CopyWebpackPlugin = require("copy-webpack-plugin");

Comment on lines +1 to +2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove unused import or uncomment webpack configuration.

The CopyWebpackPlugin is imported but not actively used since the webpack configuration is commented out. This creates unnecessary bundle size.

Either:

  1. Remove the unused import:
-const CopyWebpackPlugin = require("copy-webpack-plugin");
  1. Or uncomment and properly implement the webpack configuration below.

Committable suggestion skipped: line range outside the PR's diff.

module.exports = {
async rewrites() {
return [
Expand Down Expand Up @@ -35,4 +37,31 @@ module.exports = {
// },
]
},
// reactStrictMode: true,
// experimental: {
// serverComponentsExternalPackages: ["geoip-lite"],
// },
Comment on lines +40 to +43
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

The experimental configuration for geoip-lite should be uncommented

The verification reveals that geoip-lite is actively used in multiple API route files (pages/api/*.js) for server-side processing. Since these are API routes that import and use geoip-lite on the server side, the serverComponentsExternalPackages configuration is necessary for proper functioning.

  • Uncomment lines 40-43 in next.config.js to ensure proper handling of geoip-lite in server components:
  reactStrictMode: true,
  experimental: {
    serverComponentsExternalPackages: ["geoip-lite"],
  },
🔗 Analysis chain

Verify if experimental configuration is needed.

The commented experimental configuration for serverComponentsExternalPackages suggests that geoip-lite might need special handling for server components. This could be important for proper functioning of GeoIP features.

Let's check if this configuration is necessary:


Let me gather more information about the usage of geoip-lite in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if geoip-lite is used in server components
# Look for files that might indicate server component usage

# Check for server components using geoip-lite
rg -l "use client" | xargs rg "geoip-lite"

# Check for potential SSR/server-side usage
rg -l "getServerSideProps|getInitialProps" | xargs rg "geoip-lite"

Length of output: 904


Script:

#!/bin/bash
# Search for any imports or requires of geoip-lite
rg "require.*geoip-lite|from.*geoip-lite"

# Search for any API routes or server-side code that might use geoip-lite
fd "api" --type f --exec rg "geoip" {}

# Look for any configuration files that might reference geoip
fd -e config.js -e config.ts --exec rg "geoip" {}

Length of output: 1178

// webpack: (config, { isServer }) => {
// if (isServer) {
// config.plugins.push(
// new CopyWebpackPlugin({
// patterns: [
// {
// from: "node_modules/geoip-lite/data/geoip-country.dat",
// to: "data/geoip-country.dat",
// },
// {
// from: "node_modules/geoip-lite/data/geoip-country6.dat",
// to: "data/geoip-country6.dat",
// },
// {
// from: "node_modules/geoip-lite/data/geoip-city-names.dat",
// to: "data/geoip-city-names.dat",
// },
// ],
// }),
// );
// }
// return config;
// },
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "non-private-nft",
"version": "2.0.2",
"version": "2.0.3",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -9,7 +9,8 @@
"lint": "next lint"
},
"dependencies": {
"geoip-lite": "^1.4.5",
"copy-webpack-plugin": "^12.0.2",
"geoip-lite": "^1.4.10",
"image-to-base64": "^2.2.0",
"negotiator": "^0.6.3",
"next": "12.1.6",
Expand Down
4 changes: 2 additions & 2 deletions pages/api/demo-nft.jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default async function(req, res) {
// device: { vendor: 'Apple', model: 'iPhone', type: 'mobile' },
// cpu: { architecture: undefined }
// };

const buffer = Buffer.from(getSvg(detectedIp, geo, ua, lang, id, count));

res.statusCode = 200;
Expand All @@ -55,7 +55,7 @@ export default async function(req, res) {
optimiseCoding: false, //true: 536.8ms false: 411ms
}
const output = await sharp(buffer).resize({ width: 1000 }).jpeg(jpeg).toBuffer();


console.log(Date.now()-start);
return res.end(output);
Expand Down
2 changes: 1 addition & 1 deletion pages/api/demo-nft.svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async function(req, res) {
// detectedIp = '161.116.109.141'; // Barcelona
// detectedIp = '78.184.238.42'; // Istanbul
// detectedIp = '103.107.198.211'; // Singapore
// detectedIp = '51.154.129.107'; //
// detectedIp = '51.154.129.107'; //
//detectedIp = '2a01:110f:4407:a200:5c9e:9146:a935:a05d'; // Warsaw
const count = await insertIpToDemoAndGetCount(id, detectedIp);

Expand Down
4 changes: 2 additions & 2 deletions pages/api/ethcc-2022-nft.jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default async function(req, res) {
// device: { vendor: 'Apple', model: 'iPhone', type: 'mobile' },
// cpu: { architecture: undefined }
// };

const buffer = Buffer.from(getSvg(detectedIp, geo, ua, lang, id, count));

res.statusCode = 200;
Expand All @@ -55,7 +55,7 @@ export default async function(req, res) {
optimiseCoding: false, //true: 536.8ms false: 411ms
}
const output = await sharp(buffer).resize({ width: 1000 }).jpeg(jpeg).toBuffer();


console.log(Date.now()-start);
return res.end(output);
Expand Down
2 changes: 1 addition & 1 deletion pages/api/ethcc-2022-nft.svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async function(req, res) {
// detectedIp = '161.116.109.141'; // Barcelona
// detectedIp = '78.184.238.42'; // Istanbul
// detectedIp = '103.107.198.211'; // Singapore
// detectedIp = '51.154.129.107'; //
// detectedIp = '51.154.129.107'; //
//detectedIp = '2a01:110f:4407:a200:5c9e:9146:a935:a05d'; // Warsaw
const count = await insertIpToEthCCParis2022AndGetCount(id, detectedIp);

Expand Down
4 changes: 2 additions & 2 deletions pages/api/nft.jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default async function(req, res) {
let start = Date.now();
var detectedIp = requestIp.getClientIp(req)
const geo = geoip.lookup(detectedIp);
var country = geo?.country.toLowerCase();
var country = geo?.country.toLowerCase();

insertIpToScoreboard(detectedIp, country);
const topIPs = await getTop10Ips();
Expand All @@ -28,7 +28,7 @@ export default async function(req, res) {
optimiseCoding: false, //true: 536.8ms false: 411ms
}
const output = await sharp(buffer).resize({ width: 1000 }).jpeg(jpeg).toBuffer();


console.log(Date.now()-start);
return res.end(output);
Expand Down
2 changes: 1 addition & 1 deletion pages/api/nft.svg.js_
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async function(req, res) {

var detectedIp = requestIp.getClientIp(req)
const geo = geoip.lookup(detectedIp);
var country = geo?.country.toLowerCase();
var country = geo?.country.toLowerCase();
const topIPs = await getTop10Ips();


Expand Down
1 change: 1 addition & 0 deletions public/data/city.checksum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0bb66f0dd2c9bc09e2dce62b9137b9f35df829462df9f32f6388a571ff38eaa2 GeoLite2-City-CSV_20240716.zip
1 change: 1 addition & 0 deletions public/data/country.checksum
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e6275b1e6c08bcf0adcffa06f32993dca51390a43cf7ee7e7d7467e1fe38283a GeoLite2-Country-CSV_20240716.zip
Binary file added public/data/geoip-city-names.dat
Binary file not shown.
Binary file added public/data/geoip-city.dat
Binary file not shown.
Binary file added public/data/geoip-city6.dat
Binary file not shown.
Binary file added public/data/geoip-country.dat
Binary file not shown.
Binary file added public/data/geoip-country6.dat
Binary file not shown.
Loading