在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:eggjs/egg-core开源软件地址:https://github.com/eggjs/egg-core开源编程语言:JavaScript 99.8%开源软件介绍:egg-coreA core Pluggable framework based on koa. Don't use it directly, see egg. UsageDirectory structure
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)); EggLoaderEggLoader can easily load files or directories in your egg project. In addition, you can customize the loader with low level APIs. constructor
High Level APIsloadPluginLoad config/plugin.js loadConfigLoad config/config.js and config/{serverEnv}.js If loadControllerLoad app/controller loadMiddlewareLoad app/middleware loadApplicationExtendLoad app/extend/application.js loadContextExtendLoad app/extend/context.js loadRequestExtendLoad app/extend/request.js loadResponseExtendLoad app/extend/response.js loadHelperExtendLoad app/extend/helper.js loadCustomAppLoad app.js, if app.js export boot class, then trigger configDidLoad loadCustomAgentLoad agent.js, if agent.js export boot class, then trigger configDidLoad loadServiceLoad app/service Low Level APIsgetServerEnv()Retrieve application environment variable values via
getEggPaths()To get directories of the frameworks. A new framework is created by extending egg, then you can use this function to get all frameworks. getLoadUnits()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'
} getAppname()To get application name from package.json appInfoGet the infomation of the application
loadFile(filepath)To load a single file. Note: The file must export as a function. loadToApp(directory, property, LoaderOptions)To load files from directory in the application. Invoke loadToContext(directory, property, LoaderOptions)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();
}; loadExtend(name, target)Loader app/extend/xx.js to target, For example, this.loadExtend('application', app); LoaderOptions
TimingEggCore record boot progress with
startStart record a item. If the item exits, end the old one and start a new one.
endEnd a item.
toJSONGenerate all record items to json
Questions & SuggestionsPlease open an issue here. LicenseContributorsThis project follows the git-contributor spec, auto updated at |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论