当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

egg-core

A core Pluggable framework based on koa.
授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 吕鸿轩
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

egg-core

A core Pluggable framework based on koa.

Don't use it directly, see egg.

Usage

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

EggLoader can easily load files or directories in your egg project. In addition, you can customize the loader with low level APIs.

constructor

  • {String} baseDir - current directory of application
  • {Object} app - instance of egg application
  • {Object} plugins - merge plugins for test
  • {Logger} logger - logger instance,default is console

High Level APIs

loadPlugin

Load config/plugin.js

loadConfig

Load config/config.js and config/{serverEnv}.js

If process.env.EGG_APP_CONFIG is exists, then it will be parse and override config.

loadController

Load app/controller

loadMiddleware

Load app/middleware

loadApplicationExtend

Load app/extend/application.js

loadContextExtend

Load app/extend/context.js

loadRequestExtend

Load app/extend/request.js

loadResponseExtend

Load app/extend/response.js

loadHelperExtend

Load app/extend/helper.js

loadCustomApp

Load app.js, if app.js export boot class, then trigger configDidLoad

loadCustomAgent

Load agent.js, if agent.js export boot class, then trigger configDidLoad

loadService

Load app/service

Low Level APIs

getServerEnv()

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

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:

  1. plugin
  2. framework
  3. app

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

appInfo

Get the infomation of the application

  • pkg: package.json
  • name: the application name from package.json
  • baseDir: current directory of application
  • env: equals to serverEnv
  • HOME: home directory of the OS
  • root: baseDir when local and unittest, HOME when other environment

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 this.loadToApp('$baseDir/app/controller', 'controller'), then you can use it by app.controller.

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

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

Timing

EggCore record boot progress with Timing, include:

  • Process start time
  • Script start time(node don't implement an interface like process.uptime to record the script start running time, framework can implement a prestart file used with node --require options to set process.scriptTime)
  • Application start time
  • Load duration
  • require duration

start

Start record a item. If the item exits, end the old one and start a new one.

  • {String} name - record item name
  • {Number} [start] - record item start time, default is Date.now()

end

End a item.

  • {String} name - end item name

toJSON

Generate all record items to json

  • {String} name - record item name
  • {Number} start - item start time
  • {Number} end - item end time
  • {Number} duration - item duration
  • {Number} pid - pid
  • {Number} index - item index

Questions & Suggestions

Please open an issue here.

License

MIT

  • 我们团队现在开发的node项目都是基于koa框架实现的,虽然现在也形成了一套团队内的标准,但是在开发的过程中也遇到了一些问题: 由于没有统一的规范,新人上手和沟通成本比较高,容易出现错误 仅局限于目前需求进行设计,扩展性不高 系统部署及配置信息维护成本较高 业务代码实现起来不是很优雅,比如(1)关于文件的引入,到处的require,经常会出现忘记require或者多余的require问题(2)因为

  • 接着前篇关于 egg-core 源码分析的文章 Egg 源码分析之egg-core ,今天来看一下 egg-cluster 的源码实现逻辑。 NodeJs 中 javascript 的执行是单线程的,所以一个进程只能使用一个 CPU,为了最大可能的使用服务器资源,一般我们可以使用下面三种方式实现: 同一台机器上部署多个 Node 服务,使用不同的端口,然后用 Nginx 做负载均衡将请求转发到不同

  • https://blog.csdn.net/wan_yanyan528/article/details/71787559 https://blog.csdn.net/testcs_dn/article/details/45437903

  • 1.阿里云短信准备 参考阿里云短信 2.安装@alicloud/pop-core npm install @alicloud/pop-core 3.util/SmseCode.ts 根据openAPI的代码来修改 // eslint-disable-next-line @typescript-eslint/no-var-requires const Core = require('@aliclo

  • 一、安装egg-cors npm install egg-cors --save 二、配置plugin.js 'use strict'; /** @type Egg.EggPlugin */ exports.cors = { enable: true, package: 'egg-cors', }; 三、配置config.default.js config.security

 相关资料
  • egg-validate的定制化升级 [ ] egg-validate 基于 parameter 定制,可以用它所有的规则 [ ] 文档:https://github.com/node-modules/parameter 定制化egg-validate 建立 app.js 入口文件 'use strict' const path = require('path') class AppBootHo

  • 一个入门简单、跨平台桌面软件开发框架 2.0版 为什么使用?桌面软件(办公方向、 个人工具),仍然是未来十几年PC端需求之一,提高工作效率 简单:只需懂 JavaScript 愿景:所有开发者都能学会桌面软件研发 特性 跨平台:一套代码,可以打包成windows版、Mac版、Linux版运行 简单高效:只需学习js语言,同时支持vue、react、html等前端技术 前端独立:理论上支持任何前端技

  • egg-commerce 线上测试地址 13.229.236.130:3000 egg / mysql 开发电商平台集成支付宝面对面支付、手机网站唤醒APP支付 相关栈 node / mysql / egg / sequelizejs / redis / 支付宝支付 本地开发 1.找到config/config.default.js 和config/plugin.js确保alinode 配置和插件

  • EGG (Easy Graphical Genuine) CRM 是 cligraphcrm 项目的新名字,是一个基于Web的开源CRM系统,提供各种销售管理、电子邮件、数据导出、内部新闻等功能。

  • Egg 简介 Egg 它一个通用高效的爬虫,希望它能够替大家实现一些需求,更希望能为开源做出自己的贡献。目前,还在成长,在我的构想下,它还需要添加很多功能,我会继续完善。有任何疑问以及需求请以与作者交流:630841816@qq.com Egg是一个通用,多线程的Java爬虫框架。 Egg简单小巧,api非常简单,容易上手。 Egg性能不错,并实现多种请求方式。 能够比较快的响应使用者的需求 速度

  • 收集了 50+ 以上的彩蛋庫,可以單純使用 CDN 一行引入,也有提供 npm package 打包之後的版本,新項目持續新增中。 Quick Start wink Wink and shut their apprehensions up  <!-- There's no need to open console --><!-- Just type 'wink' in your browser -

相关阅读

相关文章

相关问答

相关文档