egg-leancloud

1.0.1 • Public • Published

egg-leancloud

NPM version build status Test coverage David deps Known Vulnerabilities npm download

LeanCloud plugin for Egg.js

Install

$ npm i egg-leancloud --save

Usage

// {app_root}/config/plugin.js
exports.leancloud = {
  enable: true,
  package: 'egg-leancloud',
};

Configuration

// {app_root}/config/config.default.js
exports.leancloud = {
  appId: '',
  appKey: '',
  masterKey: '',
};

You can config this at config.local.js and leave config.default.js empty, then will auto read config from process.env.

see config/config.default.js for more detail.

Example

app start point:

// {app_root}/app.js
 
// adjust egg env by LeanCloud env
if (!process.env.EGG_SERVER_ENV) {
  switch (process.env.LEANCLOUD_APP_ENV) {
    case 'production' :
      process.env.EGG_SERVER_ENV = 'prod';
      break;
    case 'stage':
      process.env.EGG_SERVER_ENV = 'stage';
      break;
    default:
      break;
  }
}
 
// start app
require('egg').startCluster({
  baseDir: __dirname,
  workers: process.env.LEANCLOUD_AVAILABLE_CPUS,
  port: process.env.LEANCLOUD_APP_PORT || process.env.PORT || 7001,
});

use LeanCloud api at controller:

// {app_root}/app/controller/news.js
exports.list = function* (ctx) {
  const avQuery = new ctx.AV.Query('News');
  ctx.body = yield avQuery.find();
};

use LeanCloud api at start:

// {app_root}/app.js
module.exports = app => {
  app.beforeStart(function* () {
    const avQuery = new ctx.AV.Query('User');
    app.users = yield avQuery.find();
  });
};

Questions & Suggestions

Please open an issue here.

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    0
  • 0.1.0
    1

Package Sidebar

Install

npm i egg-leancloud

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • atian25
  • sankyutang