Very powerful framework, that allow you very quick, and simple start develop any API, with just config, without any programming.
Node v8.9.4 (npm v5.7.1)
npm install @cloud-node/server@0.1.6-alpha
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
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'
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'
# ...
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'
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));
}
}
- Models
- PassportJS
- Plugins