diff --git a/jj.js b/jj.js index 33f55b0..8254c69 100644 --- a/jj.js +++ b/jj.js @@ -1,12 +1,12 @@ /** * jj.js核心库
- * {App, Controller, Db, Model, Pagination, View, Logger, Cookie, Response, Upload, Url, Middleware, Cache, Context, View, utils} + * {App, Cache, Context, Controller, Cookie, Ctx, Db, Logger, Middleware, Model, Pagination, Response, Upload, Url, View, utils} * @module core - * @type {import('./lib/types').Core} + * @type {import('./types').Core} */ module.exports = new Proxy({}, { get: (target, prop) => { - if(prop in target || typeof prop == 'symbol' || prop == 'inspect'){ + if(prop in target || typeof prop == 'symbol' || ['inspect', 'router', 'run', 'types'].includes(prop)) { return target[prop]; } prop = prop.toLowerCase(); diff --git a/lib/app.js b/lib/app.js index 4034bbb..d688746 100644 --- a/lib/app.js +++ b/lib/app.js @@ -13,6 +13,7 @@ class App extends Koa { /** * @override + * @param {...any} args - listen(port, ip, callback(err){}) */ listen(...args) { // exception @@ -45,6 +46,13 @@ class App extends Koa // router this.use(router.routes()).use(router.allowedMethods()); + // types + if(cfg_app.app_debug) { + if(require('./utils/fs').isFileSync(path.join(cfg_app.base_dir, 'jsconfig.json'))) { + require('./types')(); + } + } + // server return super.listen(...args); } diff --git a/lib/config.js b/lib/config.js index 168f69d..1af5bf4 100644 --- a/lib/config.js +++ b/lib/config.js @@ -13,9 +13,9 @@ const app = { common_app: 'common', // 公共应用,存放公共模型及逻辑 controller_folder: 'controller', //控制器目录名 - static_dir: '', // 静态文件目录,相对于应用根目录,为空或false时,关闭静态访问 + static_dir: '', // 静态文件目录,相对于应用根目录,为空时,关闭静态访问 - koa_body: null // koa-body配置参数,为''、null、false时,关闭koa-body + koa_body: null // koa-body配置参数,为null或空时,关闭koa-body } const view = { @@ -40,7 +40,7 @@ const db = { } const log = { - log_level: ['app', 'error'], // [app, error, warning, info, debug, http, sql] + log_level: ['system', 'error'], // [system, error, warning, info, debug, http, sql] log_handle: function(level, ...args) {console.log(`[${format('YY-mm-dd HH:ii:ss')}] [${level}]`, ...args.map(msg => typeof msg == 'string' ? msg : JSON.stringify(msg)));} } diff --git a/types.js b/types.js index f8fbb95..dc0d8fd 100644 --- a/types.js +++ b/types.js @@ -83,8 +83,8 @@ * @property {string} [default_action=index] - 默认方法 * @property {string} [common_app=common] - 公共应用,存放公共模型及逻辑 * @property {string} [controller_folder=controller] - 控制器目录名 - * @property {(string|boolean)} [static_dir=''] - 静态文件目录,相对于应用根目录,为空或false时,关闭静态访问 - * @property {(string|boolean|null|object)} [koa_body=null] - koa-body配置参数,为''、null、false时,关闭koa-body + * @property {string} [static_dir=''] - 静态文件目录,相对于应用根目录,为空时,关闭静态访问 + * @property {?object} [koa_body=null] - koa-body配置参数,为null或空时,关闭koa-body * @property {string} [base_dir] - 应用根目录(会自动计算) */