撸了个 eggjs+mongodb+restapi 的内容管理系统后台。求下star: https://github.com/fomenyesu/egg-mongodb-example
eggjs 确实是个不错的框架,赞一个!
egg-mongodb-example
a example of eggjs, mongodb, restful api and other stuff made it work…
Examples for egg
Usage
install mongodb start mongodb import data.json to mongodb run npm to start server
$ npm install
$ npm run dev
REST API Example
api/users GET List
{
"meta":{"total":3},
"data":[
{"_id":"58d8a899f5f2486f1f6d4236","uid":1,"name":"admin","pass":"123","status":1,"time":"1325472736"},
{"_id":"58db7828a14b14815447cf33","name":"sdf","pass":"123","status":1,"time":"1325472736","uid":3,"__v":0},
{"_id":"58db7d3bcee4d48df6f5bdfd","name":"sdddf","pass":"123","status":1,"time":"1325472736","uid":4,"__v":0}
]
}
api/users/1 GET Single Data
{
"meta":{"total":1},
"data":[
{"_id":"58d8a899f5f2486f1f6d4236","uid":1,"name":"admin","pass":"123","status":1,"time":"1325472736"}
]
}
api/users/2 PUT Update data with uid
{"name":"admin123","pass":"123","status":1,"time":"1325472736"}
api/users POST insert data
{"name":"admin123","pass":"123","status":1,"time":"1325472736"}
same with news and news_type for rest api data.
看了一眼controller,写得不漂亮
单元测试一波再求吧
发现一规律,用vue写的星星特别多,其他的都没什么星星,这到底是为啥?
新入手代码比较粗糙。不过新手也容易理解嘛。@rwing
@sunfeng90 用postman做了单元测试了。有发现什么问题吗?
@zhanzhenzhen 我也发现了,可能是接地气吧。
@zhanzhenzhen 文档我只服vuejs
- run 目录要配置下 .gitignore,这个是运行时的数据
- 建议用
egg-init --type=simple .
来初始化项目 "egg-view-react": "^0.0.1",
没用到不用引入- config 里面有很多没用到的可以删掉
- 单元测试直接用
supertest
@fomenyesu 这么说,是因为文档写得好,所以大家才对vue有好感的?
mark
@atian25 感谢大神的建议,删除了一些无用代码逻辑,感觉清爽很多。哈哈~
@zhanzhenzhen 很少框架可以不用一天就读完文档的了。
@fomenyesu postman做单元测试?这个不是谷歌用来测试请求接口的吗?
这个不是用来请求接口用的吗?和单元测试没有关系吧
@sunfeng90 因为这个项目主要是做 restful api 接口的,所以当时是用postman来测试接口是不是正常。 验证接口业务正常而已。再细致的就要用supertest了
嗯,我指的的是Mocha和SuperTest
@Mwangzhi 你是王zhi?
Mocha和SuperTest 单元测试已经加上 顺便说一句,用egg-bin 做test 果然方便。 @sunfeng90