-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9358bdc
commit a161d85
Showing
1 changed file
with
3 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,118 +27,7 @@ npm run-script start-server | |
npm run-script debug-server | ||
``` | ||
|
||
### API | ||
### Help and Documentation | ||
|
||
The node-web-cluster is shipped with a MVC api ready to work, as simple as this: | ||
|
||
/api/controllers/user.js | ||
|
||
```javascript | ||
policy(req, res).check("authenticated", function() { | ||
|
||
var _user = req.cookies.user; | ||
|
||
if(_user.password) | ||
delete _user.password; | ||
|
||
res.json({ | ||
|
||
result: "success", | ||
user: _user | ||
}); | ||
|
||
}) | ||
|
||
``` | ||
|
||
#### Models | ||
|
||
Are defined in ```/api/models/``` as ```[user]_model.js```. Example: ```/api/models/user_model.js```. | ||
|
||
File structure: | ||
```javascript | ||
module.exports = { | ||
|
||
name: { | ||
|
||
required: true, | ||
type: "string" | ||
|
||
}, | ||
|
||
email: { | ||
|
||
required: true, | ||
type: "email" | ||
|
||
}, | ||
|
||
password: { | ||
|
||
required: true, | ||
type: "password" | ||
|
||
}, | ||
|
||
access_token: { | ||
|
||
required: true, | ||
type: "string" | ||
|
||
}, | ||
|
||
role: { | ||
|
||
required: true, | ||
type: "string", | ||
default: "user" | ||
}, | ||
|
||
toJSON: function(_this){ | ||
|
||
delete _this.password; | ||
return JSON.stringify(_this); | ||
} | ||
} | ||
``` | ||
|
||
Then, you can create a new object based on the model you defined above. | ||
|
||
```javascript | ||
var user = model.create("user", { | ||
|
||
name: "name", | ||
email: "[email protected]", | ||
password: "abcd1234", | ||
access_token: "01234567890" | ||
|
||
}); | ||
|
||
console.log(user.email); // prints: "[email protected]" | ||
``` | ||
|
||
#### Controllers | ||
|
||
Are defined in ```/api/controllers/``` as ```[name].js```. Example: ```/api/controllers/user.js```. | ||
|
||
File structure: ```/api/controllers/test.js``` | ||
|
||
```javascript | ||
module.exports = { | ||
|
||
// route: /test | ||
index: function(req, res) { | ||
res.json({ | ||
test: "ok" | ||
}) | ||
}, | ||
|
||
// route: /test/get | ||
get: function(req, res) { | ||
res.json({ | ||
test: "ok" | ||
}) | ||
}, | ||
|
||
} | ||
``` | ||
* [Wiki](https://github.com/luiseduardobrito/node-web-cluster/wiki) | ||
* [Issues](https://github.com/luiseduardobrito/node-web-cluster/issues) |