-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,770 additions
and
951 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# v0.9.0 / 2024-02-06 | ||
1. 支持jsdoc,完善vscode代码提示 | ||
2. 系统核心库app由对象改为class,使用const app = new App() | ||
3. 修复Logger类输出格式化bug,log函数参数调换 | ||
4. 系统日志配置,默认输出['app', 'error']级别的日志 | ||
5. 系统级屏蔽favicon.ico请求 | ||
6. 系统loader支持并优先加载文件 | ||
7. 依赖升级@koa/router v10.1.1 -> v12.0.1 | ||
8. 依赖升级koa v2.13.4 -> v2.15.0 | ||
9. node版本要求 >= v12.7.0 | ||
|
||
# v0.8.8 / 2022-09-07 | ||
1. 第一个tag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"resolveJsonModule": true, | ||
"checkJs": true | ||
}, | ||
"exclude": ["node_modules", "docs", "./lib/ctx.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
source: { | ||
include: ['./jj.js', './lib'], | ||
includePattern: '.+\\.js(doc)?$', | ||
}, | ||
plugins: [ | ||
"jsdoc-tsimport-plugin" | ||
], | ||
templates: { | ||
cleverLinks: true, | ||
monospaceLinks: true, | ||
}, | ||
opts: { | ||
recurse: true, | ||
destination: './docs', | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,53 @@ | ||
const path = require('path'); | ||
const Koa = require('koa'); | ||
const app = new Koa(); | ||
const {app: cfg_app} = require('./config'); | ||
const Logger = require('./logger'); | ||
const Response = require('./response'); | ||
const router = require('./router'); | ||
const pjson = require('../package.json'); | ||
|
||
app.run = (...args) => { | ||
// exception | ||
app.use(async (ctx, next) => { | ||
ctx.APP_TIME = new Date(); | ||
ctx.APP_VERSION = pjson.version; | ||
|
||
try { | ||
await next(); | ||
} catch (err) { | ||
Logger.error(...err.stack.split("\n")); | ||
if(cfg_app.app_debug) { | ||
new Response(ctx).exception(err); | ||
} else { | ||
ctx.response.status = err.statusCode || err.status || 500; | ||
ctx.body = 'Internal Server Error'; | ||
/** | ||
* @extends Koa | ||
*/ | ||
class App extends Koa | ||
{ | ||
/** | ||
* @override | ||
*/ | ||
listen(...args) { | ||
// exception | ||
this.use(async (ctx, next) => { | ||
ctx.APP_TIME = Date.now(); | ||
ctx.APP_VERSION = pjson.version; | ||
|
||
try { | ||
await next(); | ||
} catch (err) { | ||
Logger.error(...err.stack.split("\n")); | ||
if(cfg_app.app_debug) { | ||
new Response(ctx).exception(err); | ||
} else { | ||
ctx.response.status = err.statusCode || err.status || 500; | ||
ctx.body = 'Internal Server Error'; | ||
} | ||
} | ||
} | ||
|
||
const ms = new Date() - ctx.APP_TIME; | ||
Logger.http(`${ctx.method} ${ctx.status} ${ctx.url} - ${ms}ms`); | ||
}); | ||
const ms = Date.now() - ctx.APP_TIME; | ||
Logger.http(`${ctx.method} ${ctx.status} ${ctx.url} - ${ms}ms`); | ||
}); | ||
|
||
// static | ||
cfg_app.static_dir && app.use(require('koa-static')(path.join(cfg_app.base_dir, cfg_app.static_dir))); | ||
// static | ||
cfg_app.static_dir && this.use(require('koa-static')(path.join(cfg_app.base_dir, cfg_app.static_dir))); | ||
|
||
// koa-body | ||
cfg_app.koa_body && app.use(require('koa-body')(cfg_app.koa_body)); | ||
// koa-body | ||
cfg_app.koa_body && this.use(require('koa-body')(cfg_app.koa_body)); | ||
|
||
// router | ||
app.use(router.routes()).use(router.allowedMethods()); | ||
// router | ||
this.use(router.routes()).use(router.allowedMethods()); | ||
|
||
// server | ||
app.listen(...args); | ||
|
||
// run once | ||
delete app.run; | ||
// server | ||
return super.listen(...args); | ||
} | ||
} | ||
|
||
module.exports = app; | ||
module.exports = App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.