File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 11import { readFile } from 'node:fs/promises' ;
2+ import { createRequire } from 'node:module' ;
23import path from 'node:path' ;
34import { dirname } from 'node:path' ;
45import { fileURLToPath } from 'node:url' ;
@@ -29,8 +30,22 @@ async function loadDatabase(): Promise<ReaderModel | null> {
2930 console . log ( 'GeoLite2-City.mmdb loaded (local)' , dbPathLocal ) ;
3031 return Reader . openBuffer ( dbBuffer ) ;
3132 } catch {
32- console . error ( 'GeoLite2-City.mmdb not found' , { dbPath, dbPathLocal } ) ;
33- return null ;
33+ // Try node_modules resolution (for Vercel/serverless environments)
34+ try {
35+ const require = createRequire ( import . meta. url ) ;
36+ const packagePath = require . resolve ( '@openpanel/geo/package.json' ) ;
37+ const packageDir = path . dirname ( packagePath ) ;
38+ const nodeModulesPath = path . join ( packageDir , filename ) ;
39+ const dbBuffer = await readFile ( nodeModulesPath ) ;
40+ console . log (
41+ 'GeoLite2-City.mmdb loaded (node_modules)' ,
42+ nodeModulesPath ,
43+ ) ;
44+ return Reader . openBuffer ( dbBuffer ) ;
45+ } catch {
46+ console . error ( 'GeoLite2-City.mmdb not found (node_modules)' ) ;
47+ return null ;
48+ }
3449 }
3550 }
3651}
You can’t perform that action at this time.
0 commit comments