master
parent
3ad6a21e87
commit
a6fd16d542
14 changed files with 213 additions and 101 deletions
@ -0,0 +1,17 @@ |
|||||||
|
module.exports = { |
||||||
|
apps: [ |
||||||
|
{ |
||||||
|
name: 'qry-python-js', // 应用的名称
|
||||||
|
script: './app.js', // Express 应用的入口文件
|
||||||
|
instances: 'max', // 启动的实例数('max' 表示使用所有可用的 CPU 核心)
|
||||||
|
exec_mode: 'cluster', // 使用集群模式
|
||||||
|
env: { |
||||||
|
NODE_ENV: 'development', // 开发环境的环境变量
|
||||||
|
}, |
||||||
|
env_production: { |
||||||
|
NODE_ENV: 'production', // 生产环境的环境变量
|
||||||
|
PORT: 80, // 自定义环境变量示例
|
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}; |
@ -0,0 +1,40 @@ |
|||||||
|
const path = require("node:path"); |
||||||
|
|
||||||
|
|
||||||
|
const AreaNameEnum = Object.freeze({ |
||||||
|
YUN_NAN: Object.freeze({ |
||||||
|
AREA_CODE: '5300', |
||||||
|
AREA_NAME: 'yunnan', |
||||||
|
JS_FILE: path.resolve(__dirname, '../public/yunnan/MO5zzCMcub4d.b4c45da.js'), |
||||||
|
}), |
||||||
|
HU_BEI: Object.freeze({ |
||||||
|
AREA_CODE: '4200', |
||||||
|
AREA_NAME: 'hubei', |
||||||
|
JS_FILE: path.resolve(__dirname, '../public/hubei/5PXGXoOF7eGJ.ed63b8f.js'), |
||||||
|
}), |
||||||
|
|
||||||
|
getByAreaCode(areaCode) { |
||||||
|
if (areaCode == null) { |
||||||
|
return Object(); |
||||||
|
} |
||||||
|
for (const key in this) { |
||||||
|
if (this[key] && this[key].AREA_CODE === areaCode.toString()) { |
||||||
|
return this[key]; |
||||||
|
} |
||||||
|
} |
||||||
|
return Object(); |
||||||
|
}, |
||||||
|
getByAreaName(areaName) { |
||||||
|
if (areaName == null) { |
||||||
|
return Object(); |
||||||
|
} |
||||||
|
for (const key in this) { |
||||||
|
if (this[key] && this[key].AREA_NAME === areaName.toString()) { |
||||||
|
return this[key]; |
||||||
|
} |
||||||
|
} |
||||||
|
return Object(); |
||||||
|
}, |
||||||
|
}); |
||||||
|
|
||||||
|
module.exports = AreaNameEnum; |
@ -0,0 +1,19 @@ |
|||||||
|
const os = require('node:os'); |
||||||
|
|
||||||
|
class IpUtil { |
||||||
|
static networkInterfaces = os.networkInterfaces(); // 私有静态属性,用于缓存网络接口信息
|
||||||
|
|
||||||
|
static getLocalIPs() { |
||||||
|
let ipAddresses = []; |
||||||
|
for (const face in this.networkInterfaces) { |
||||||
|
for (const address of this.networkInterfaces[face]) { |
||||||
|
if (address.family === 'IPv4' && !address.internal) { |
||||||
|
ipAddresses.push(address.address); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return ipAddresses; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
module.exports = IpUtil; |
@ -0,0 +1,92 @@ |
|||||||
|
/** |
||||||
|
* // 使用示例
|
||||||
|
* async function f() { |
||||||
|
* let store = new Store(); |
||||||
|
* |
||||||
|
* setTimeout(() => { |
||||||
|
* store.set('111', '111') |
||||||
|
* }, 3000) |
||||||
|
* |
||||||
|
* console.log('尝试获取值') |
||||||
|
* let val = await store.waitGetAndDelete('111',1000,10); |
||||||
|
* |
||||||
|
* console.log(val) |
||||||
|
* console.log(store) |
||||||
|
* } |
||||||
|
* f() |
||||||
|
* @returns {Promise<void>} |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Store |
||||||
|
*/ |
||||||
|
class Store { |
||||||
|
store = new Map() |
||||||
|
|
||||||
|
sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); |
||||||
|
|
||||||
|
set(key, value) { |
||||||
|
this.store.set(key, value) |
||||||
|
} |
||||||
|
|
||||||
|
get(key) { |
||||||
|
return this.store.get(key) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取等待 |
||||||
|
* @param key |
||||||
|
* @param timeout 等待时长 |
||||||
|
* @param reTry 重试次数 |
||||||
|
* @returns {Promise<any|null>} |
||||||
|
*/ |
||||||
|
async waitGet(key, timeout = 100, reTry = 10) { |
||||||
|
if (timeout <= 0) { |
||||||
|
timeout = 10; |
||||||
|
} |
||||||
|
// 没有时长限制的等待
|
||||||
|
if (reTry === -1) { |
||||||
|
while (true) { |
||||||
|
await this.sleep(timeout) |
||||||
|
let val = this.store.get(key); |
||||||
|
if (val != null) { |
||||||
|
return val; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
// 有时长限制的等待
|
||||||
|
for (let i = reTry; i > 0; i--) { |
||||||
|
let val = this.store.get(key) |
||||||
|
if (val != null) { |
||||||
|
return val |
||||||
|
} |
||||||
|
await this.sleep(timeout) |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
async waitGetAndDelete(key, timeout = 100, reTry = 10) { |
||||||
|
let value = await this.waitGet(key, timeout, reTry); |
||||||
|
if (value != null) { |
||||||
|
this.store.delete(key) |
||||||
|
} |
||||||
|
return value |
||||||
|
} |
||||||
|
|
||||||
|
getAndDelete(key) { |
||||||
|
let value = this.store.get(key); |
||||||
|
this.store.delete(key) |
||||||
|
return value |
||||||
|
} |
||||||
|
|
||||||
|
has(key) { |
||||||
|
return this.store.has(key) |
||||||
|
} |
||||||
|
|
||||||
|
delete(key) { |
||||||
|
return this.store.delete(key) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
module.exports = Store |
||||||
|
|
@ -1,16 +0,0 @@ |
|||||||
// const paths = require('./paths');
|
|
||||||
// const pkg = require(paths.package);
|
|
||||||
// const log4js = require('log4js');
|
|
||||||
//
|
|
||||||
// log4js.configure({
|
|
||||||
// appenders: {
|
|
||||||
// console: { type: 'console' }
|
|
||||||
// },
|
|
||||||
// categories: {
|
|
||||||
// default: { appenders: ['console'], level: 'info' }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// const logger = log4js.getLogger(pkg.name);
|
|
||||||
// logger.level = pkg.logLevel || 'debug';
|
|
||||||
//
|
|
||||||
// module.exports = logger;
|
|
@ -1,24 +0,0 @@ |
|||||||
// const path = require('path');
|
|
||||||
// const fs = require('fs');
|
|
||||||
//
|
|
||||||
// const appDirectory = (() => {
|
|
||||||
// // 返回项目根目录
|
|
||||||
// const plist = path.resolve(__dirname).split(path.sep);
|
|
||||||
// while (!fs.existsSync(path.resolve(plist.join(path.sep), 'package.json'))) {
|
|
||||||
// plist.pop();
|
|
||||||
// if (plist.length === 0) return false;
|
|
||||||
// }
|
|
||||||
// return plist.join(path.sep);
|
|
||||||
// })();
|
|
||||||
// const resolveApp = (...relativePath) => path.resolve(appDirectory, ...relativePath);
|
|
||||||
//
|
|
||||||
// module.exports = {
|
|
||||||
// basePath: resolveApp('.'),
|
|
||||||
// modulePath: resolveApp('node_modules'),
|
|
||||||
// binPath: resolveApp('node_modules', '.bin/'),
|
|
||||||
// package: resolveApp('package.json'),
|
|
||||||
// resolve: resolveApp,
|
|
||||||
// handlerPath: resolveApp('handler'),
|
|
||||||
// configPath: resolveApp('config'),
|
|
||||||
// configResolve: (...p) => resolveApp('config', ...p),
|
|
||||||
// };
|
|
Loading…
Reference in new issue