Skip to content

alexmarch/cloud-node

Repository files navigation

cloud-node-server

Cloud-node - web framework build on top of ExpressJS

Logo

npm npm

Very powerful framework, that allow you very quick, and simple start develop any API, with just config, without any programming.

Versions

Node v8.9.4 (npm v5.7.1)

Install

  npm install @cloud-node/server@0.1.6-alpha

How to use

  const { server } = require('@cloud-node/server');
  server.start({
    pm2: process.env.NODE_ENV === 'development' ? true : false
  });

If option pm2 is enabled in console you will see pm2 monitor image

Setup

Routes

Create configuration file for routes config/routes.yml with next structure

routes:
  - namespace:
      name: 'apis'
      resources: # - Resource will provice all RESTful API methods for controller home
        - home:
      cloud: # - Endpoint will look like: (GET) /apis/cloud/index
        - get:
            action: 'index'
        - get:
            as: 'home' # - Endpoint will look like: (GET) /apis/cloud/home
            controller: 'cloud'
            action: 'home'
        - all: # - Endpoint will allow all request methods
            controller: 'cloud'
            action: 'all'

Polices

Protect you route with polices, create file config/polices.js

  module.exports = {
    isAuth: function (req, res, next) {
      return req.user.isAuth ? next() : next('User not authorized.') ) // Checking if user authorized
    }
  }
  - get:
      action: 'index'
      polices:
          - 'isAuth'
          # ...

Controllers

Create controller file in the application root folder controllers/cloud.js

  module.exports = {
    index: function (req, res) { res.ok('Hi, cloud-node.') }
  }

routes configuration

  - get: # - Endpoint will look like: (GET) /apis/cloud/index/:id
      as: 'index/:id'
      controller: 'cloud'
      action: 'index'

Models

You can subscribe your models in config routes.yml

 model: 
  - 'user'
  - 'profile'

then you can get access to the model instance from your controller method

  module.exports = {
    index: function (req, res) { 
      this.models.user.all().then(users => res.json(users));
    }
  }

@TODO list:

  • Models
  • PassportJS
  • Plugins

About

Cloud-node - web framework build on top of ExpressJS

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published