Compare commits

..

No commits in common. "81585f81f7fa9de0fae87b63c6a9177fa365f87f" and "9156beda016ab13d7357a8222e363a9bb304bbfc" have entirely different histories.

3 changed files with 5 additions and 37 deletions

9
app.js
View File

@ -1,6 +1,6 @@
const Koa = require("koa");
const requter = require("./bin/router.js");
dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/',"ceshikaoshi")
dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/ceshikaoshi',"ceshikaoshi")
// console.log(requter)
// import requter from "./bin/router"
const app = new Koa();
@ -41,13 +41,8 @@ app.use(async (ctx, next) => {
// getResponseHeader('myData')可以返回我们所需的值
//https://www.rails365.net/articles/cors-jin-jie-expose-headers-wu
ctx.set("Access-Control-Expose-Headers", "myData");
if(ctx.method == "OPTIONS"){
ctx.body = ""
}else{
await next();
}
})
app.use(async (ctx,next)=>{
// await next();

View File

@ -6,11 +6,11 @@ function addMapping(router, mapping) {
if (url.startsWith('GET ')) {
var path = url.substring(4);
router.get(path, mapping[url]);
console.log(`register URL mapping: GET ${path}`);
// console.log(`register URL mapping: GET ${path}`);
} else if (url.startsWith('POST ')) {
var path = url.substring(5);
router.post(path, mapping[url]);
console.log(`register URL mapping: POST ${path}`);
// console.log(`register URL mapping: POST ${path}`);
} else {
console.log(`invalid URL: ${url}`);
}

View File

@ -76,35 +76,8 @@ let findshop = async (ctx, next) => {
ctx.body = await dbs.find("shop")
}
let logins = async(ctx,next)=>{
let {user , pwd} = ctx.request.body
console.log(123)
if(user == "admin" && pwd == "123"){
ctx.body = JSON.stringify({
code: 200,
msg:"登录成功",
data:{
name:"admin",
age:18,
quxain: "admin"
}
})
}else{
ctx.body = JSON.stringify({
code: 200,
msg:"登录成功",
data:{
name:"user",
age:18,
quxain: "user"
}
})
}
}
module.exports = {
"GET /":index,
"POST /addshop": addshop,
"GET /findshop": findshop,
"POST /login": logins
"GET /findshop": findshop
}