Gathering detailed insights and metrics for egg-core
Gathering detailed insights and metrics for egg-core
Gathering detailed insights and metrics for egg-core
Gathering detailed insights and metrics for egg-core
npm install egg-core
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
218 Stars
337 Commits
92 Forks
35 Watching
15 Branches
45 Contributors
Updated on 30 Aug 2024
TypeScript (99.57%)
JavaScript (0.34%)
Shell (0.09%)
Cumulative downloads
Total Downloads
Last day
4.2%
3,272
Compared to previous day
Last week
-3.3%
21,163
Compared to previous week
Last month
10%
98,819
Compared to previous month
Last year
-58.3%
1,146,311
Compared to previous year
19
A core plugin framework based on @eggjs/koa. Support Commonjs and ESM both by tshy.
Don't use it directly, see egg.
Directory structure
1āāā package.json 2āāā app.ts (optional) 3āāā agent.ts (optional) 4āāā app 5| āāā router.ts 6ā āāā controller 7ā ā āāā home.ts 8| āāā extend (optional) 9ā | āāā helper.ts (optional) 10ā | āāā filter.ts (optional) 11ā | āāā request.ts (optional) 12ā | āāā response.ts (optional) 13ā | āāā context.ts (optional) 14ā | āāā application.ts (optional) 15ā | āāā agent.ts (optional) 16ā āāā service (optional) 17ā āāā middleware (optional) 18ā ā āāā response_time.ts 19ā āāā view (optional) 20| āāā layout.html 21ā āāā home.html 22āāā config 23| āāā config.default.ts 24ā āāā config.prod.ts 25| āāā config.test.ts (optional) 26| āāā config.local.ts (optional) 27| āāā config.unittest.ts (optional) 28ā āāā plugin.ts
Then you can start with code below
1import { EggCore as Application } from '@eggjs/core'; 2 3const app = new Application({ 4 baseDir: '/path/to/app' 5}); 6app.ready(() => { 7 app.listen(3000); 8});
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.ts
Load config/config.ts and config/{serverEnv}.ts
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.ts
Load app/extend/context.ts
Load app/extend/request.ts
Load app/extend/response.ts
Load app/extend/helper.ts
Load app.ts, if app.ts export boot class, then trigger configDidLoad
Load agent.ts, if agent.ts 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.
1{ 2 path: 'path/to/application', 3 type: 'app' 4}
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.
1// define service in app/service/query.ts 2export default class Query { 3 constructor(ctx: Context) { 4 super(ctx); 5 // get the ctx 6 } 7 8 async get() {} 9} 10 11// use the service in app/controller/home.ts 12export default async (ctx: Context) => { 13 ctx.body = await ctx.service.query.get(); 14};
Loader app/extend/xx.ts to target, For example,
1await 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.
Made with contributors-img.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 5/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More