Skip to content

Instantly share code, notes, and snippets.

@yaroslav-ilin
Last active March 8, 2021 06:31
Show Gist options
  • Save yaroslav-ilin/d790596bd4728271209d70c9cc2f422f to your computer and use it in GitHub Desktop.
Save yaroslav-ilin/d790596bd4728271209d70c9cc2f422f to your computer and use it in GitHub Desktop.
Running node-maxmind in browser
import { Buffer } from 'buffer';
import * as maxmind from 'maxmind';
export async function load() {
const response = await fetch('./data/GeoLite2-Country.mmdb');
const buf = Buffer.from(await response.arrayBuffer());
buf.utf8Slice = function (start, end) {
return this.toString('utf8', start, end);
};
return new maxmind.Reader(buf);
}
const path = require('path');
module.exports = {
node: {
net: 'empty',
},
module: {
rules: [
{
test: path.resolve(__dirname, './node_modules/maxmind/lib/fs.js'),
use: 'null-loader',
},
],
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment