
Company News
Andrew Becherer Joins Socket as Chief Information Security Officer
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.
Based on koa, provide convenience for the middle layer development of a series of functional suite.
Based on koa, provide convenience for the middle layer development of a series of functional suite.
$ npm install --save sword-plus
Here is a blog for sword-plus. You can enjoy it.
sword-plus.jsSwordPlus的Error封装。用于统一分配error。
目前SwordPlus Error的type有如下几种,
RouterRouter用于解析koa的包装后的请求。
其中有两个主要方式,
parse,用于解析路由provider,用于聚合业务类,并启动与对应路由匹配的业务逻辑DEFAULT_CONFIG,
var DEFAULT_CONFIG = {
folder: '', // 路由目录
routerMap: { // 默认的路由配置表
'/': 'index'
},
cache: true, // 是否应用缓存,这里缓存的对象为具体的业务类,而不是业务类实例
logger: true, // 是否记录日志
'404': '/404.html', // 默认的404页面
'500': '/500.html' // 默认的500页面
}
PuggerPugger主要用于在服务的渲染Jade/Pug模板
DEFAULT_CONFIG,
var DEFAULT_CONFIG = {
global: {}, // 渲染时额外填充的全局数据
folder: '', // 模板目录
suffix: '.pug', // 默认的模板文件后缀
suffixList: ['.pug', '.jade'], // 支持的模板文件后缀
cache: true, // 是否应用缓存,这里缓存的对象为compile过的模板内容
logger: false // 是否记录日志
}
LoggerLogger将所有的日志分为如下几大类(category),
其中第一行的6种其实是bunyan自带日志等级的alias,第二行是根据不同业务场景抽象出来的。
每一条日志都是一个record抽象,每个record实例在category的维度下,还会有level的区分,常用的level有如下几种
DEFAULT_CONFIG,
var DEFAULT_CONFIG = {
folder: '', // 写日志目录
slice: true, // 是否分割日志,默认按天
prefix: 'sp-logger', // 日志文件名前缀
suffix: '.log', // 日志文件后缀
name: 'sp-logger-20161101+0800', // 日志record对象的名称
src: false, // 是否记录源文件代码行信息
saveInterval: false, // 6e4 // 是否按照某一周期写日志
saveBuffer: false, // 100 // 是否按照某一buffer缓冲写日志
durationLimit: 3e3, // 5e3 // request和response日志类型的耗时限制
reqDetail: true, // 是否记录request日志类型的详情
resDetail: true, // 是否记录response日志类型的详情
action: true, // 是否启用交互日志类型记录
actDetail: true // 是否记录action日志类型的详情
}
HandlerHandler是业务类模型的顶层抽象。
所有经过Router解析之后,都会通过Handler来派生出具体的业务类,以便在Router.provider中使用。 在Handler中可以使用内部扩展或者外部拓展(Handler.inject),来增加所有业务类即可使用的功能方法。
此外,Handler中对几个套件的实例对象做了转发,使得在具体的业务类中可以使用他们。
Handler中提供如下几个方法,
inherits,在Router解析完毕之后,在Router.provider中通过此方法生成具体的业务类Clazz。dispatch,在业务类中对get和post请求进行转发。inject,在server启动时,可以根据需要注入外部拓展,一旦注入,则在所有生成的业务类中都可使用。ConnectorConnector封装了node->rest层,UI层->node层的请求操作。内部使用了node-fetch。
允许在操作请求时,记录请求日志。
var DEFAULT_CONFIG = {
hostname: '', // rest服务的hostname
port: 80, // rest服务的port
timeout: 5e3, // 请求timeout市场限制
logger: false // 是否记录请求日志
}
see demo folder for more detail.
MIT © gejiawen
FAQs
Based on koa, provide convenience for the middle layer development of a series of functional suite.
We found that sword-plus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.