@bbyy/vera

A web framework based egg.js

Usage no npm install needed!

<script type="module">
  import bbyyVera from 'https://cdn.skypack.dev/@bbyy/vera';
</script>

README

Vera

A web framework extends Egg.js

Usage

npm i -S @bbyy/vera
# package.json
"egg": {
  "framework": "@bbyy/vera"
}

插件

清单

名称 node_modules enable
ejs egg-view-ejs true
ue @bbyy/egg-ue true
io egg-socket.io false
redis egg-redis false
sessionRedis egg-session-redis false

默认配置

// plugin.js
module.exports = {
  ejs: {
    enable: true,
    package: 'egg-view-ejs',
  },
  ue: {
    enable: true,
    package: '@bbyy/egg-ue',
  },
  io: {
    enable: false,
    package: 'egg-socket.io',
  },
  redis: {
    enable: false,
    package: 'egg-redis',
  },
  sessionRedis: {
    enable: false,
    package: 'egg-session-redis',
  },
};

// config.default.js
module.exports = () => {
  const config = {
    siteFile: {
      '/favicon.ico': readFileSync(join(__dirname, 'favicon.png')),
    },
    httpclient: {
      request: {
        timeout: [ 30000, 600000 ],
      },
    },
    io: {
      namespace: {
        '/': {
          connectionMiddleware: [],
          packetMiddleware: [],
        },
      },
      redis: {
        host: '127.0.0.1',
        port: 6379,
        auth_pass: '',
        db: 0,
      },
    },
    redis: {
      client: {
        host: '127.0.0.1',
        port: 6379,
        password: '',
        db: 0,
      },
    },
  };

  return config;
};

继承自egg

插件

  • onerror
  • session
  • i18n
  • watcher
  • multipart
  • security
  • development
  • logrotator
  • schedule
  • static
  • view
  • jsonp

中间件

  • meta
  • siteFile
  • notfound
  • bodyParser
  • overrideMethod

Questions & Suggestions

Please open an issue here.

参考

@bbyy/egg-ue

ctx.helper

// urlconcat
ctx.helper.urlconcat('http://localhost:8080/', 'api/search', 'something', '?a=b&b=c')
// http://localhost:8080/api/search/something?a=b&b=c

// pagination

// uuid
ctx.helper.uuid.v4()
ctx.helper.uuid.v1()

// lodash
ctx.helper._.pick
ctx.helper._.assign
...

// xor
ctx.helper.xor([ 2, 1, 3 ], [ 2, 4, 6, 1 ]);
// {toDel: [3], toAdd: [4, 6]}

// exec
await ctx.helper.exec(`ls ${__dirname}`);
// 执行结果

// password
const originalPassword = '1234';
const hashPassword = await ctx.helper.password.hash(originalPassword);
assert(originalPassword !== hashPassword);
assert(await ctx.helper.password.compare(originalPassword, hashPassword));
assert(!(await ctx.helper.password.compare(originalPassword, hashPassword + '123')));