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-fortress

v1.0.3

Published

## 项目目的

Downloads

4

Readme

Eggjs项目基础框架

项目目的

  1. 抽离各个Eggjs项目中的重复代码,提高项目代码复用
  2. 项目公共依赖抽离,方便统一管理依赖,包括模块版本升级,规范插件
  3. 规范项目异常、返回结构,统一项目风格,提高项目可维护性

NPM地址:https://www.npmjs.com/package/egg-fortress

框架特点

  1. 集成 lodashmoment到helper对象, egg-corsegg-validate插件

使用方式:


// lodash
ctx.helper._  

// moment
ctx.helper.moment
  1. 扩展ctx方法,JSON数据返回使用统一的格式 

统一的格式:


{
  "code": 0,
  "data": {},
  "msg": ""
}

说明:code为0,msg为空表示正常返回,code不为0,表示请求异常,msg为异常提示

扩展的方法:


// 设置正常响应
// data: 返回的数据,不传则不返回该字段
// status: HttpStatus Code 默认为200
ctx.success(data, status);

// 设置错误响应,一般不需要手动调用,只需要在Controller、Service throw error即可
// 返回结构中 code 为 err.code 如不存在则默认 -1
// 返回结构中 msg 为 err.message 如不不存在则默认 未知异常
// 响应HttpStatus Code 为 err.status 如不存在则默认为 500
ctx.error(err);
  1. 添加配置的方式生成系统error类型

使用方式:


// config.xxx.js
// name: error名称
// code: error编码
// status: 响应HttpStatus Code
config.errors = [{
  name: 'InvalidParam',
  code: 101,
  status: 500,
}];

// Controller
throw new ctx.app.errors.InvalidParam('用户名格式不正确')

使用方式

  1. 修改package.json文件添加:

"egg": {
  "framework": "egg-fortress"
}
  1. 修改应用中的引用的基类

// Controller
const Controller = require('egg-fortress').Controller;

class MyController extends Controller {}

// Service
const Service = require('egg-fortress').Service;

class MyService extends Service {}