npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

egg-syllabus-framework

v1.0.38

Published

汕大课程表egg框架

Downloads

163

Readme

egg-syllabus-framework

快速开始

下载egg模板,并安装依赖

$ npm i egg-init -g
$ egg-init <文件夹名字> --type=simple
$ cd <文件夹名字>
$ npm i

安装egg-syllabus-framework

$ npm install egg-syllabus-framework --save

修改package.json,在JSON最外层(与name同级)新增如下内容:

// package.json
"egg": {
  "framework": "egg-syllabus-framework"
},

启动框架

$ npm run dev

打开 http://127.0.0.1:7001 体验

特性

默认关闭CSRF校验

对于小程序来说,小程序没有cookie,不会出现CSRF,并且由于没有cookie,无法通过CSRF校验 如果客户端为浏览器,应该开启CSRF校验。开启方式如下

// config/config.default.js
config.security = {
    csrf: false
}

日志记录

请求响应日志

自动打印所有请求的参数和响应结果到日志文件中

屏蔽

对于部分不必要的日志记录,可以屏蔽。 例如页面的响应结果,必定为页面的HTML代码,不需要输出,输出到日志中反而会占用过多的日志行数,淹没正常日志 屏蔽方式如下,ignore填写需要屏蔽的请求的url,支持字符串、正则、函数,函数需要返回true 或false

// config/config.default.js
config.response = {
  ignore:[
      '/favicon.ico'
  ]
}

请求链路日志

ControllerService的方法被调用时,能够自动打印出日志 注意:经过的中间件链路不会打印日志

请求ID

待完善

错误返回

我们约定了统一的错误返回格式

{
	code: "01020304",
	message: "error message"
}

当code为0时代表没有错误

错误码格式

我们约定了如下的错误码格式:

  • 1-2位 —— 代表发生错误的后台,在线上服务中,我们的后台服务可能不止一个
  • 3-4位 —— 01 代表 错误发生在Controller,02 代表错误发生在service,03代表错误发生在Middleware,04相关数据库相关的错误,其他待补充
  • 5-6位 —— 具体的业务错误码

如果某一错误码片段为全0,则代表该部分的错误码没有被登记

配置

在使用错误码前需要进行配置,登记错误码的映射规则,需要在全局配置文件下新增如下配置

// config/config.default.js
config.errCode = {
    APP_ERROR_CODE: '01',   // 应用错误码,错误码1-2位,其他为3-6位
    NOT_REGISTER_ERROR: '0000', // 未登记默认错误码
}

抛出错误

我们封装了一个方法ctx.helper.createError(),用来生成带有错误码信息的Error对象

/**
 * 创建一个带有错误码的Error对象
 * @param msg 错误信息
 * @param code 5-8位错误码
 * @param arg_props 其他混入到Error对象的属性
 * @returns {Error} 返回带错误码的Error对象
 */
createError(msg, code, arg_props) {}

我们只需要这样调用即可抛出一个带有错误码的Error对象,如果该对象没有被手动捕获,将会被框架捕获并返回给用户

throw ctx.helper.createError('error message', ctx.config.errCode.YOUR_ERROR)

给客户端返回错误信息

默认不发送错误信息说明到客户端 可以通过在配置里设置showErrorMsgtrue,将ctx.helper.createError()创建的错误对象的错误信息返回到客户端

config.showErrorMsg = true

代码风格

变量名

  • 对象和数组不同单词用驼峰
  • 其他使用下不同单词用下划线分割
  • 常量需要大写

待完善文档

  • 小程序登录服务
  • 工具包,加密解密,带错误码的错误对象

待完成功能

  • 静态页面中间件,改善HTML的请求日志