Spoiler: it's possible.
An experiment of trying to run node-maxmind Node.js library in a browser.
See https://ilin.dk/weblog/maxmind-in-browser for more details about the files below.
See the live version running on https://nilfalse.com/labs/geoip/
Spoiler: it's possible.
An experiment of trying to run node-maxmind Node.js library in a browser.
See https://ilin.dk/weblog/maxmind-in-browser for more details about the files below.
See the live version running on https://nilfalse.com/labs/geoip/
| 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', | |
| }, | |
| ], | |
| }, | |
| }; |