diff --git a/src/server/router/serverStatus.ts b/src/server/router/serverStatus.ts index 38b0647..3f0cb67 100644 --- a/src/server/router/serverStatus.ts +++ b/src/server/router/serverStatus.ts @@ -2,13 +2,11 @@ import { Router } from 'express'; import { body, header, param, validate } from '../middleware/validate'; import { recordServerStatus } from '../model/serverStatus'; import fs from 'fs-extra'; -import path from 'path'; +import { libraryPath } from '../utils/lib'; export const serverStatusRouter = Router(); -const installScript = fs.readFileSync( - path.resolve(process.cwd(), '../../scripts/install.sh') -); +const installScript = fs.readFileSync(libraryPath.installScript); serverStatusRouter.post( '/report', diff --git a/src/server/utils/detect.ts b/src/server/utils/detect.ts index 4ba7ac3..89aa040 100644 --- a/src/server/utils/detect.ts +++ b/src/server/utils/detect.ts @@ -11,8 +11,8 @@ import { MOBILE_OS, MOBILE_SCREEN_WIDTH, } from './const'; -import path from 'path'; import maxmind, { Reader, CityResponse } from 'maxmind'; +import { libraryPath } from './lib'; let lookup: Reader; @@ -104,9 +104,7 @@ export async function getLocation(ip: string, req: Request) { // Database lookup if (!lookup) { - const dir = path.join(process.cwd(), 'geo'); - - lookup = await maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb')); + lookup = await maxmind.open(libraryPath.geoPath); } const result = lookup.get(ip); diff --git a/src/server/utils/lib.ts b/src/server/utils/lib.ts new file mode 100644 index 0000000..8a07c1c --- /dev/null +++ b/src/server/utils/lib.ts @@ -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'), +};