[关闭]
@yumewang 2017-06-30T06:44:37.000000Z 字数 2994 阅读 1047

First see Koa

HXkid


20170626 ~ 20170630 (5days: Koa for 园葵API + mysql )

node-style-guide: 
    https://github.com/dead-horse/node-style-guide

1. 准备工作

    1. 学习MySQL:http://www.runoob.com/mysql/mysql-tutorial.html
    2. 浏览 KOA,及 Nodejs
        https://github.com/17koa/koa-generator-examples
        http://i5ting.github.io/stuq-koa/index.html
    3. 学习 ES6 新语法:async, generator 等
        http://es6.ruanyifeng.com/
    4. 系统学习 HTTP 请求
        https://developer.mozilla.org/zh-CN/docs/Web/HTTP
        https://foofish.net/http-request-process.html
        http://www.ruanyifeng.com/blog/2016/08/http.html
        https://github.com/muwenzi/Program-Blog/issues/35
    5. 安装MySQL可视化工具 Sequel
    6. 使用 Postman api请求工具(或HTTPie),用于验证 API 正确性
    7. https://github.com/muwenzi/Program-Blog

2. 实现图集列表及分页-HTTP GET (Sequelize)

    将会用到 Sequelize: 
        findAll() - 查询多条数据
        findAndCount() - 分页查询
            https://itbilu.com/nodejs/npm/V1PExztfb.html#api-findAndCount

    Github 库参考(嘉伟):https://github.com/adamchenjiawei/koa2_study (仅供参考)

    1. 创建数据库:hbb_growup_wx_garden
        新建数据库
            数据库名称:hbb_growup_wx_garden
            数据库编码:  
            Character Set:utf8mb4
            Collation:utfmb4_general_ci
    2. 导入 嘉伟提供的 园葵 数据库 sql
    3. koa-generator 命令创建项目:koa2 koaDemo (项目名koaDemo)
    4. 变更项目结构为 MVC 结构 (参考 嘉伟的实现)
    5. Koa, 数据库MySQL,如何使用 Sequelize 完成数据连接
        http://docs.sequelizejs.com/

    6. 如何定义 model 数据定义 - 图集表 model/albums.js
        理解 数据类型,配置,主键定义等
    7. 定义图集 Service: service/albums_cervie.js
    8. 定义图集 Controller:controller/albums_controller.js
    9. 定义图集 routes:routes/index
    10. 实现 获取所有图集列表(Json对象)
    11. 实现图集列表分页
    12. 利用 mount-koa-routes 实现自动挂载路由
        http://i5ting.github.io/stuq-koa/moa2/mount-routes.html

加强练习:
1) Sequelize 的使用:联表查询(albums 表 + photos 表:albums 与 photos 是一对多的关系),无误差实现:园葵列表
2) 再次熟悉 Sequelize
3) 本日回顾

3. 实现图集新增-HTTP POST

    API: http://123.57.6.211:9090/%E5%9B%AD%E8%91%B5-%E5%9B%BE%E9%9B%86%E6%96%B0%E5%A2%9E.html

    1. 简单 POST 请求
    2. 使用 koa-multer 实现本地上传文件
        参考:http://i5ting.github.io/stuq-koa/koa-practice/http-practice.html
        npm install --save koa-multer
        http://i5ting.github.io/stuq-koa/koa-practice/http-practice.html
    3. 图片上传新增API - 七牛云(请 嘉伟 提供)

    4. 明确如何解析 http 请求参数(File)

    About koa-multer:
        https://github.com/koa-modules/multer
        如何处理图片上传时异常,及文件大小限制?
        https://github.com/koa-modules/multer/blob/master/test/error-handling.js
        https://github.com/expressjs/multer/blob/master/doc/README-zh-cn.md

4. 实现日志输出,及部署(环境数据库连接可配置)

    使用模板:
        http://mozilla.github.io/nunjucks/api.html
        https://github.com/strawbrary/koa-nunjucks-2
    koa2进阶学习笔记: https://chenshenhai.github.io/koa2-note/
    1. 图片上传新增API - 七牛云(异步请求)(请 嘉伟 提供)
        accessKey:A7x1E0ygz5XWHtbCiu8t4_6NqptWQ7Ma8oY3ysMN
        SecretKey:CGC-eriN03MfpJluhizyMFWMs0mfeyIpaHCuUTCi
        文档地址: https://developer.qiniu.com/

        上传空间: hbb-growup-wechat
        文件访问域名 host: http://oibzvf99m.bkt.clouddn.com

    2. View 实现(新 删 改 查,完整的数据操作)自定 (昨日挪动)
    3. View 模板选择(嘉伟 选择)自定(昨日挪动) 

    1. 部署:环境数据库连接可配置
    2. 了解 nodemon, pm2 是何?
        http://web.jobbole.com/89255/
        https://github.com/Unitech/pm2
        https://wohugb.gitbooks.io/pm2/content/index.html
    3. 日志输出,不同环境的配置
    4. 引入 Sequelize migration : Sequelize-cli
    5. Koa 进阶: 
        session 处理
        cache 缓存:redis

5. 预留时间

    1. 微信:后端推送消息 及 获取用户信息
    2. 项目实战:
        http://i5ting.github.io/stuq-koa/koa-in-action/index.html
    3. Koa 进阶: 
        session 处理
        cache 缓存:redis
    4. 了解 Express
    5. 如何处理跨域请求配置

6?. 下一步 - Koa?

修改views,自定义重启nodemon:
http://bubkoo.com/2014/12/02/use-nodemon-with-node-applications/
https://github.com/remy/nodemon/blob/master/doc/cli/config.txt

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注