帐户页面调用本地服务器的update方法更新,一直报服务器异常错误
来源:
jennylove
2016-11-28
6回答
-
在 use logger 之前,先把 keys 加上试试
app.keys = ['secret', 'key']
012016-12-06 -
Scott
2016-12-05
这个不是入口文件的代码吧,就是启动服务器的那个文件的代码
00 -
Scott
2016-12-05
把你的 app.js 代码贴一下,看看中间件的加载顺序有没有问题
00 -
Scott
2016-12-04
哦,我说错了,以为是微信的课程,把模块都删除再重新安装一遍,然后服务也重新跑起来看看,把加入的中间件也都删除调试看看,最好是能定位到是哪个代码调用时候除了问题。
012016-12-04 -
jennylove
提问者
2016-12-05
'use strict'
var fs = require('fs');
var path = require('path');
var mongoose = require('mongoose');
var db = 'mongodb://localhost/imoocApp';
mongoose.Promise = require('bluebird');
mongoose.connect(db);
var models_path = path.join(__dirname,'/app/models');
var walk = function(modelPath){
fs
.readdirSync(modelPath)
.forEach(function(file){
var filePath = path.join(modelPath,'/'+file);
var stat = fs.statSync(filePath);
if(stat.isFile()){
if(/(.*)\.(js|coffee)/.test(file)){
require(filePath)
}
}else if (stat.isDirectory()) {
walk(filePath)
}
})
}
var koa = require('koa');
var logger = require('koa-logger');
var session = require('koa-session');
var bodyParser = require('koa-bodyparser');
var app = koa();
app.use(logger())
app.use(session(app))
app.use(bodyParser())
var router = require('./config/routes')()
app
.use(router.routes())
.use(router.allowedMethods());
app.listen(12345)
00 -
jennylove
提问者
2016-12-05
exports.signature = function *(next){
var body = this.request.body;
var cloud = body.cloud;
var data;
if(cloud === 'qiniu'){
data = robot.getQiniuToken(body);
}else{
data = robot.getCloudinaryToken(body)
}
this.body = {
success: true,
data: data
}
}
exports.hasBody = function *(next){
var body = this.request.body || {};
console.log(body);
if(Object.keys(body).length === 0){
this.body = {
success: false,
error: '是不是漏掉什么了'
}
return next;
}
yield next
}
exports.hasToken = function *(next){
var accessToken = this.query.accessToken;
if(!accessToken){
accessToken = this.request.body.accessToken;
}
if(!accessToken){
this.body = {
success: false,
error: '钥匙丢了'
}
return next;
}
var user = yield User.findOne({
accessToken: accessToken
}).exec()
if(!user){
this.body = {
success: false,
error: '没有登录'
}
return next;
}
this.session = this.session || {};
this.session.user = user;
yield next
}
00
相似问题