fix: fix library path load problem
This commit is contained in:
parent
f5f0a560f1
commit
c049a62493
@ -2,13 +2,11 @@ import { Router } from 'express';
|
|||||||
import { body, header, param, validate } from '../middleware/validate';
|
import { body, header, param, validate } from '../middleware/validate';
|
||||||
import { recordServerStatus } from '../model/serverStatus';
|
import { recordServerStatus } from '../model/serverStatus';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import { libraryPath } from '../utils/lib';
|
||||||
|
|
||||||
export const serverStatusRouter = Router();
|
export const serverStatusRouter = Router();
|
||||||
|
|
||||||
const installScript = fs.readFileSync(
|
const installScript = fs.readFileSync(libraryPath.installScript);
|
||||||
path.resolve(process.cwd(), '../../scripts/install.sh')
|
|
||||||
);
|
|
||||||
|
|
||||||
serverStatusRouter.post(
|
serverStatusRouter.post(
|
||||||
'/report',
|
'/report',
|
||||||
|
@ -11,8 +11,8 @@ import {
|
|||||||
MOBILE_OS,
|
MOBILE_OS,
|
||||||
MOBILE_SCREEN_WIDTH,
|
MOBILE_SCREEN_WIDTH,
|
||||||
} from './const';
|
} from './const';
|
||||||
import path from 'path';
|
|
||||||
import maxmind, { Reader, CityResponse } from 'maxmind';
|
import maxmind, { Reader, CityResponse } from 'maxmind';
|
||||||
|
import { libraryPath } from './lib';
|
||||||
|
|
||||||
let lookup: Reader<CityResponse>;
|
let lookup: Reader<CityResponse>;
|
||||||
|
|
||||||
@ -104,9 +104,7 @@ export async function getLocation(ip: string, req: Request) {
|
|||||||
|
|
||||||
// Database lookup
|
// Database lookup
|
||||||
if (!lookup) {
|
if (!lookup) {
|
||||||
const dir = path.join(process.cwd(), 'geo');
|
lookup = await maxmind.open(libraryPath.geoPath);
|
||||||
|
|
||||||
lookup = await maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = lookup.get(ip);
|
const result = lookup.get(ip);
|
||||||
|
6
src/server/utils/lib.ts
Normal file
6
src/server/utils/lib.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
export const libraryPath = {
|
||||||
|
installScript: path.resolve(process.cwd(), '../../scripts/install.sh'),
|
||||||
|
geoPath: path.resolve(process.cwd(), '../../geo/GeoLite2-City.mmdb'),
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user