Giter VIP home page Giter VIP logo

egg-leancloud's Introduction

egg-leancloud

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

LeanCloud plugin for Egg.js

Maintainer Required.
If you are interested in picking up maintenance, file an issue at eggjs/egg.

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

egg-leancloud's People

Contributors

atian25 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.