koa-scheme中间件报错~
app.js文件:
var app = require("koa")(),
Jade = require("koa-jade"),
router = require("koa-router")(),
bodyParser = require("koa-bodyparser"),
scheme = require("koa-scheme");
jade = new Jade({
viewPath: __dirname + '/template',
debug: true,
pretty: true,
compileDebug: true,
locals : {
"name": "Jade"
},
noCache : true,
app: app
});
var staticServer = require("koa-static");
app.use(bodyParser());
//加载表态文件
app.use(staticServer(__dirname + '/common'));
app.use(router.routes());
router
.get("/",function* (next){
this.render("login.jade",{name:"Jade"},null,true);
});
app.use(scheme(__dirname + '/scheme.js'),{debug:true});
package.json文件:
{
"name": "koa",
"version": "1.0.0",
"private": true,
"author": {
"name": "Zander",
"email": "[email protected]"
},
"dependencies": {
"crypto": "0.0.3",
"install": "^0.5.4",
"koa": "^1.1.2",
"koa-bodyparser": "^2.0.1",
"koa-etag": "^2.1.1",
"koa-jade": "^2.1.0",
"koa-router": "^5.4.0",
"koa-scheme": "^2.2.0",
"koa-static": "^2.0.0",
"mysql-co": "0.0.4",
"validator": "^5.1.0"
},
"devDependencies": {},
"scripts": {
"start": "node app.js"
}
}
login页面发送的post请求:
this.submitBtn.addEventListener("click",() => {
let xhr = new XMLHttpRequest();
xhr.open('POST',"http://localhost:3000/login");
xhr.onload = function(request) {
let response = request.currentTarget.response || request.target.responseText;
console.log(response);
};
xhr.send("username=" + that.userName.value + "&password=" + that.userPassword.value);
//xhr.send({"username":that.userName.value,"password":that.userPassword.value});
return xhr;
})
scheme.js 文件:
/**
* Created by guysz on 2016/3/4.
*/
var validator = require("validator");
module.exports = {
"/": {
"response": {
"status":200
}
},
"/login": {
"request": {
"method":"POST",
"body":{
"username":"[a-zA-Z]+",
"password":"[a-zA-Z]+"
}
},
"response": {
"status":200
}
};
页面中发送请求的时候,请求400,会返回 body.username : Not exist!
11 回复