基于Promise的Node.js MVC框架 ThinkJS

码农软件 · 软件分类 · Node.js 扩展 · 2019-04-15 16:58:04

软件介绍

ThinkJS 是一个快速、简单的基于MVC和面向对象的轻量级Node.js开发框架,遵循MIT协议发布。秉承简洁易用的设计原则,在保持出色的性能和至简的代码同时,注重开发体验和易用性,为WEB应用开发提供强有力的支持。

thinkjs里面很多特性来源于ThinkPHP,同时根据Node.js的特点,使用了Promise, WebSocket等特性,让代码更简洁、优雅。

使用 ES6/7 特性来开发项目

借助 Babel 编译,可以在项目中大胆使用 ES6/7 所有的特性,无需担心哪些特性当前版本不支持。尤其是使用 async/await 或者 */yield 来解决异步回调的问题。

//user controller, home/controller/user.js
export default class extends think.controller.base {
  //login action
  async loginAction(self){
    //如果是get请求,直接显示登录页面
    if(this.isGet()){
      return this.display();
    }
    //这里可以通过post方法获取所有的数据,数据已经在logic里做了校验
    let data = this.post();
    let md5 = think.md5("think_" + data.pwd);
    //用户名和加密后的密码去匹配数据库中对于的条目
    let result = await this.model("user").where({name: data.name, pwd: md5}).find();
    //如果未匹配到任何数据,表示用户名或者密码错误
    if(think.isEmpty(result)){
      return this.fail("login fail");
    }
    //获取到用户信息后,将用户信息写入session
    await this.session("userInfo", result);
    return this.success();
  }
}

本文地址:https://codercto.com/soft/d/3648.html

Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

Lincoln Stein、Doug MacEachern / O'Reilly Media, Inc. / 1999-03 / USD 39.95

Apache is the most popular Web server on the Internet because it is free, reliable, and extensible. The availability of the source code and the modular design of Apache makes it possible to extend Web......一起来看看 《Writing Apache Modules with Perl and C》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具