Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
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').Application;
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
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
Load agent.js
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 load |
target | Object | attach object from loaded files |
ignore | String | ignore the files when load |
initializer | Function | custom file exports, receive two parameters, first is the inject object, second is an options object that contain path |
lowercaseFirst | Boolean | determine whether the fist letter is lowercase |
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 |
Please open an issue here.
FAQs
A core Pluggable framework based on koa
The npm package egg-core receives a total of 16,166 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.