GithubHelp home page GithubHelp logo

react-koa-mongodb's Introduction

做的一个ToDoList,这个是一个整体前后端框架的测试

  • 前端: react + react-router + redux + antd
  • 后端: node + koa
  • 数据: mongoDB + mongoose
  • 构建工具: npm + webpack

运行

  • 安装依赖

    npm install

  • 运行数据库

    mongod --dbpath c:\data\koa

  • 运行服务器

    npm run server

  • 运行前端

    npm start

##mongoose

Schema 是定义数据模型,数据操作方法,继承方法

var mongoose = require('mongoose')
var UserSchema = new mongoose.Schema({...数据模型})
UserSchema.pre('save, function(next){...预操作;next()})
UserSchema.statics()

Model 是生成聚集集合,继承Schema方法

var mongoose = require('mongoose')
var UserSchema = require('../schemas/user')
var User = mongoose.model('User', UserSchema)
module.exports = User

Controll 是暴露的操作具体接口方法

var User = mongoose.model('User')
// User有静态方法,根据模板新生成的数据对象user,
var _user = req.body.user
user = new User(_user)

版本 node v6.10.3 npm v3.10.10

   工具 utils 对请求的封装   ---------> 处理函数   action redux数据行为封装  获取数据后通过action属性给到reducer
   然后 ----------------> reducer返回新的数据,给state,然后connect后,在属性中拿到数据

配置 当前端运行时,发出http请求时,在webpack中配置了proxy代理,会将符合条件的请求(api)代理到本地启动的localhost:3000端口node服务器, 这样就可以处理8080端口到3000端口的跨域问题

数据保存 使用mongoose来定义需要存储的数据模型

react-koa-mongodb's People

Contributors

haiplay avatar jixianu avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Forkers

kangofchen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.