You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Controllers (the C in MVC) are the principal objects in your Sails application that are responsible for responding to requests from a web browser, mobile application or any other system capable of communicating with a server. They often act as a middleman between your models and views. For many applications, the controllers will contain the bulk of your project’s business logic.
Controllers are comprised of a set of methods called actions. Actions are bound to routes in your application, so that when a client requests the route, the action is executed to perform some business logic and send a response.
Sails.js 请先做个自我介绍吧
Sails.js
ThinkJS
对比下 ThinkJS, 可以看到 Sails 的功能更为强大, 当然也就会更加地复杂...
新建一个项目跑起来
具体文档请参考官方的 Getting Started, 新建项目成功后访问
http://localhost:1337/
来查看效果, 以下示例基于[email protected]
版本由于 Sails 没有自带 autorealod 功能, 开发阶段你修改代码后必须每次重启
sails lift
, 这样实在是太麻烦了, 因此推荐开发阶段推荐使用 nodemon 执行nodemon app.js
来自动重启, 另外sails console
是一个非常实用的命令行工具.官方提供的文档只是做了分类, 没有向导似的文档, 让你可以一步接一步从入门到进阶, 因此文档看起来会让人觉得混乱费劲, 建议先从 Controllers 看起.
Controllers
完整的 controller 示例
列举了一般开发中所需要的功能
重点内容
听听吐槽
其他选择
Express application generator
提供了很好的路由模块化组织方式, 具体代码可以参考 expressjs/generator
Express Middleware
路由中间件
Koa 没有自带路由中间件, 可以使用 koajs/route 这个简单的实现, 不过一般推荐使用 koa-router 功能更全.
Joi Object schema description language and validator for JavaScript objects.
Boom HTTP-friendly error objects
The text was updated successfully, but these errors were encountered: