Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
egg-core
Advanced tools
A core Pluggable framework based on koa.
Don't use it directly, see egg.
Directory structure
├── package.json
├── app.js (optional)
├── agent.js (optional)
├── app
| ├── router.js
│ ├── controller
│ │ └── home.js
| ├── extend (optional)
│ | ├── helper.js (optional)
│ | ├── filter.js (optional)
│ | ├── request.js (optional)
│ | ├── response.js (optional)
│ | ├── context.js (optional)
│ | ├── application.js (optional)
│ | └── agent.js (optional)
│ ├── service (optional)
│ ├── middleware (optional)
│ │ └── response_time.js
│ └── view (optional)
| ├── layout.html
│ └── home.html
├── config
| ├── config.default.js
│ ├── config.prod.js
| ├── config.test.js (optional)
| ├── config.local.js (optional)
| ├── config.unittest.js (optional)
│ └── plugin.js
Then you can start with code below
const Application = require('egg-core').EggCore;
const app = new Application({
baseDir: '/path/to/app'
});
app.ready(() => app.listen(3000));
EggLoader can easily load files or directories in your egg project. In addition, you can customize the loader with low level APIs.
Load config/plugin.js
Load config/config.js and config/{serverEnv}.js
If process.env.EGG_APP_CONFIG
is exists, then it will be parse and override config.
Load app/controller
Load app/middleware
Load app/extend/application.js
Load app/extend/context.js
Load app/extend/request.js
Load app/extend/response.js
Load app/extend/helper.js
Load app.js, if app.js export boot class, then trigger configDidLoad
Load agent.js, if agent.js export boot class, then trigger configDidLoad
Load app/service
Retrieve application environment variable values via serverEnv
. You can access directly by calling this.serverEnv
after instantiation.
serverEnv | description |
---|---|
default | default environment |
test | system integration testing environment |
prod | production environment |
local | local environment on your own computer |
unittest | unit test environment |
To get directories of the frameworks. A new framework is created by extending egg, then you can use this function to get all frameworks.
A loadUnit is a directory that can be loaded by EggLoader, cause it has the same structure.
This function will get add loadUnits follow the order:
loadUnit has a path and a type. Type must be one of those values: app, framework, plugin.
{
path: 'path/to/application',
type: 'app'
}
To get application name from package.json
Get the infomation of the application
package.json
package.json
To load a single file. Note: The file must export as a function.
To load files from directory in the application.
Invoke this.loadToApp('$baseDir/app/controller', 'controller')
, then you can use it by app.controller
.
To load files from directory, and it will be bound the context.
// define service in app/service/query.js
module.exports = class Query {
constructor(ctx) {
// get the ctx
}
get() {}
};
// use the service in app/controller/home.js
module.exports = function*() {
this.body = this.service.query.get();
};
Loader app/extend/xx.js to target, For example,
this.loadExtend('application', app);
Param | Type | Description |
---|---|---|
directory | String/Array | directories to be loaded |
target | Object | attach the target object from loaded files |
match | String/Array | match the files when load, default to **/*.js (if process.env.EGG_TYPESCRIPT was true, default to `[ '**/*.(js |
ignore | String/Array | ignore the files when load |
initializer | Function | custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an options object that contain path |
caseStyle | String/Function | set property's case when converting a filepath to property list. |
override | Boolean | determine whether override the property when get the same name |
call | Boolean | determine whether invoke when exports is function |
inject | Object | an object that be the argument when invoke the function |
filter | Function | a function that filter the exports which can be loaded |
EggCore record boot progress with Timing
, include:
process.uptime
to record the script start running time, framework can implement a prestart file used with node --require
options to set process.scriptTime
)require
durationStart record a item. If the item exits, end the old one and start a new one.
End a item.
Generate all record items to json
Please open an issue here.
This project follows the git-contributor spec, auto updated at Wed Nov 24 2021 22:24:39 GMT+0800
.
4.30.0 (2022-12-19)
features
0e48956
] - feat: enable asyncLocalStorage by default (#251) (fengmk2 <fengmk2@gmail.com>)fixes
1d7d19b
] - fix: fix call legacyReadyCallback with options (#250) (killa <killa123@126.com>)features
d4080c0
] - feat: add legacy timing (#249) (killa <killa123@126.com>)features
7750ebc
] - feat: dump plugin info when it implicit enable by dependents plugin (#248) (TZ | 天猪 <atian25@qq.com>)fixes
0c571d8
] - fix: appInfo.scope no value (#247) (一剑 <answord@163.com>)features
7c6353f
] - feat: extract plugin loader method for override (#246) (TZ | 天猪 <atian25@qq.com>)features
8ae1aad
] - feat: add load plugin methods (#245) (吖猩 <whx89768@alibaba-inc.com>)others
7c4707c
] - Create codeql-analysis.yml (fengmk2 <fengmk2@gmail.com>)fixes
f8c069b
] - fix: validate plugin.package (#244) (TZ | 天猪 <atian25@qq.com>)others
970134b
] - chore: update node engines to 8.9.0+ (#243) (TZ | 天猪 <atian25@qq.com>)02bb843
] - refactor: use require.resolve instead of fs.exists (#238) (TZ | 天猪 <atian25@qq.com>)features
f8169f1
] - feat: support plugin strict config (#240) (吖猩 <whx89768@alibaba-inc.com>)fixes
a9fc514
] - fix: plugin loader support pnpm (#239) (hyj1991 <yeekwanvong@gmail.com>)features
43f15ad
] - feat: support pnpm node_modules style (#237) (TZ | 天猪 <atian25@qq.com>)others
4b523c5
] - deps: use globby@10.0.2 to fix security warning (fengmk2 <fengmk2@gmail.com>)26ec6e4
] - ci: remove travis (#233) (hyj1991 <yeekwanvong@gmail.com>)features
9684589
] - feat: expose set config meta (#227) (TZ | 天猪 <atian25@qq.com>)fixes
19a60de
] - fix: should end some timings (#226) (TZ | 天猪 <atian25@qq.com>)features
9e3b454
] - feat: support process.env.EGG_APP_CONFIG (#225) (TZ | 天猪 <atian25@qq.com>)b207f89
] - feat: timing support Process Start/Script Start (#222) (killa <killa123@126.com>)features
9b371fa
] - feat: support enable/disable/clear timing (#224) (TZ | 天猪 <atian25@qq.com>)fixes
f704e99
] - fix: this type in EggLoader (#223) (maxming <maxming2333@gmail.com>)others
8cb0a6e
] - chore(typings): add EggLoader interface (#221) (Kiho · Cham <monkindey@163.com>)fixes
2935e16
] - fix: fix before close order (#219) (killa <killa123@126.com>)fixes
77e11f5
] - fix: fix ready callback id (#214) (killa <killa123@126.com>)others
5bb4fe4
] - deps: upgrade dependencies (#215) (Haoliang Gao <sakura9515@gmail.com>)fixes
947292c
] - fix: ignore console instance on config meta (#211) (fengmk2 <fengmk2@gmail.com>)features
515d50f
] - feat: debug middleware enter log on every request (#210) (fengmk2 <fengmk2@gmail.com>)others
1ba4d7c
] - fix(d.ts): caseStyle should return array (#209) (JimmyDaddy <heyjimmygo@gmail.com>)fixes
6bbbca2
] - fix: change non-exports type to interface (#206) (吖猩 <whxaxes@qq.com>)features
0b7b6e6
] - feat: custom loader support exports (#205) (TZ | 天猪 <atian25@qq.com>)01201c3
] - feat: improve d.ts (#204) (吖猩 <whxaxes@qq.com>)fixes
ab3ffcf
] - fix: customLoader should not overwrite the existing property (#203) (Haoliang Gao <sakura9515@gmail.com>)features
3299be4
] - feat: add new mixin loadCustomLoader in Loader (#202) (Haoliang Gao <sakura9515@gmail.com>)fixes
d7c2c9a
] - fix: don't print when plugins that disabled by app is empty (#201) (Haoliang Gao <sakura9515@gmail.com>)others
6d34013
] - deps: use egg router 2.0.0 (#200) (fengmk2 <fengmk2@gmail.com>)features
2eb0076
] - feat: support options.env to specific server env (#199) (Yiyu He <dead_horse@qq.com>)others
8bfbbea
] - chore: upgrade egg-router (#198) (Yiyu He <dead_horse@qq.com>)others
fcdf663
] - chore: use @eggjs/router instead of koa-router (#197) (Yiyu He <dead_horse@qq.com>)29118e5
] - Chore (gitignore, file_loader.test.js): Update files (#195) (Maledong <maledong_github@outlook.com>)others
35ed3fa
] - refactor(jest-support): Replace require.extensions with Module._extensions (#196) (Gray <njugray@gmail.com>)features
90cafae
] - feat: loader support load file without extname (#194) (吖猩 <whxaxes@qq.com>)features
df1cc5b
] - feat: support jest (#188) (吖猩 <whxaxes@qq.com>)others
b123b61
] - chore: resolve EggApplication is not a Class (#186) (zhangdianpeng <hzzhangdianpeng@corp.netease.com>)features
fdc1ee5
] - feat: add 'configWillLoad' hook to lifecycle (#187) (fengmk2 <fengmk2@gmail.com>)fixes
58a49e4
] - fix(lifecycle): forbid adding hook after initialization (#184) (initialwu)others
9c16f2e
] - chore(eslint): set root=true to stop looking in parent folders (#183) (initialwu)fixes
0b0c23f
] - fix: app.js export can be non-function (#182) (Yiyu He <dead_horse@qq.com>)fixes
33c07db
] - fix: ensure treat function app.js as configDidLoad (#181) (Yiyu He <dead_horse@qq.com>)features
9d2f2fc
] - feat: impl boot methods (#171) (killa <killa123@126.com>)others
b71074d
] - fix(config) removes whitespace from both ends of serverEnv (#180) (supperchong <2267805901@qq.com>)ae38fa4
] - chroe: add more comments for toAsyncFunction and toPromise (Maledong <maledong_github@outlook.com>)4d4113c
] - style(core): beautify reg and add .idea to ignore (#179) (Army <army8735@qq.com>)features
bb24396
] - feat: pick commit from 3.x (#166) (Haoliang Gao <sakura9515@gmail.com>)others
72d33ae
] - test: add testcase for loadExtend with function call (#167) (Haoliang Gao <sakura9515@gmail.com>)fixes
4508c36
] - fix: toAsyncFunction can't pass is.asyncFunction() (#159) (Khaidi Chu <i@2333.moe>)features
7f087e7
] - feat: change assert to warning (#157) (Axes <whxaxes@qq.com>)features
2c6fbbf
] - feat: loader support custom extension (#156) (Axes <whxaxes@qq.com>)fixes
046ffdd
] - fix: should not load optional plugin & their deps (#154) (zōng yǔ <gxcsoccer@users.noreply.github.com>)features
5323a9e
] - feat: add patch method for update (egg#1793) (#150) (吴建金 <mosaic101@foxmail.com>)fixes
2926058
] - fix: mutli-path register. (#151) (SuperEVO <zhang740@qq.com>)fixes
b41891d
] - fix: fix plugin sequence bug (#152) (zōng yǔ <gxcsoccer@users.noreply.github.com>)4f1c19a
] - fix: only filter the plugin which is disabled by app (#145) (#146) (Haoliang Gao <sakura9515@gmail.com>)others
3384a87
] - refactor: replace indexOf()
with includes()
(#148) (m31271n <m31271n@2players.studio>)613f236
] - docs: fix typo (#147) (m31271n <m31271n@2players.studio>)25b728c
] - refactor: warning when the plugin disabled by app is enabled implicitly (#141) (Haoliang Gao <sakura9515@gmail.com>)features
cbcf402
] - feat: support options.serverScope for egg-mock (#143) (Yiyu He <dead_horse@qq.com>)fixes
b327145
] - fix: should load router middleware in beforeStart (#139) (Yiyu He <dead_horse@qq.com>)187fdec
] - fix: check whether controller exists (#138) (TZ | 天猪 <atian25@qq.com>)fixes
035098c
] - fix: adjust implicitly enable logic (#135) (zōng yǔ <gxcsoccer@users.noreply.github.com>)features
4979b98
] - feat: export controller function's FULLPATH (#131) (#132) (fengmk2 <fengmk2@gmail.com>)features
4bb7472
] - feat: export egg utils (#130) (Yiyu He <dead_horse@qq.com>)others
a02df89
] - test: use async function instead of generator function (#128) (Yiyu He <dead_horse@qq.com>)others
ba0c9b9
] - refactor: upgrade to koa@2 and koa-router@7 [BREAKING_CHANGE] (#125) (Yiyu He <dead_horse@qq.com>)features
c944f79
] - feat: export app.options (#127) (Haoliang Gao <sakura9515@gmail.com>)features
08b498f
] - feat: toAsyncFunction compact with async function (#126) (Yiyu He <dead_horse@qq.com>)features
f9b4ae8
] - feat: add toPromise and toAsyncFunction (#124) (Yiyu He <dead_horse@qq.com>)others
1eaa0c6
] - refactor: use utility to read json (#122) (Haoliang Gao <sakura9515@gmail.com>)features
eedfd3d
] - feat: support serverScope (#120) (Haoliang Gao <sakura9515@gmail.com>)features
c2dec90
] - feat(core): adding support to register inherited methods when loading controllers (#119) (lkspc <lkspc@qq.com>)FAQs
A core Pluggable framework based on koa
The npm package egg-core receives a total of 17,300 weekly downloads. As such, egg-core popularity was classified as popular.
We found that egg-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 14 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.