2
This commit is contained in:
parent
2ef9823b2f
commit
f458c472f7
9
app.js
9
app.js
@ -1,6 +1,6 @@
|
||||
const Koa = require("koa");
|
||||
const requter = require("./bin/router.js");
|
||||
dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/ceshikaoshi',"ceshikaoshi")
|
||||
dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/',"ceshikaoshi")
|
||||
// console.log(requter)
|
||||
// import requter from "./bin/router"
|
||||
const app = new Koa();
|
||||
@ -41,8 +41,13 @@ 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();
|
||||
|
@ -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}`);
|
||||
}
|
||||
|
@ -76,8 +76,35 @@ 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
|
||||
"GET /findshop": findshop,
|
||||
"POST /login": logins
|
||||
}
|
Loading…
Reference in New Issue
Block a user