Compare commits
4 Commits
81585f81f7
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 8765de91b3 | |||
| 3fc2d12c10 | |||
| d0868e6043 | |||
| 5fa9fd13f2 |
6
app.js
6
app.js
@@ -4,6 +4,8 @@ dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/',"ceshikaoshi")
|
|||||||
// console.log(requter)
|
// console.log(requter)
|
||||||
// import requter from "./bin/router"
|
// import requter from "./bin/router"
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
|
const bodyParser = require('koa-bodyparser');
|
||||||
|
app.use(bodyParser());
|
||||||
app.use(async (ctx, next) => {
|
app.use(async (ctx, next) => {
|
||||||
// 允许来自所有域名请求
|
// 允许来自所有域名请求
|
||||||
ctx.set("Access-Control-Allow-Origin", "*");
|
ctx.set("Access-Control-Allow-Origin", "*");
|
||||||
@@ -40,6 +42,7 @@ app.use(async (ctx, next) => {
|
|||||||
// 需要获取其他字段时,使用Access-Control-Expose-Headers,
|
// 需要获取其他字段时,使用Access-Control-Expose-Headers,
|
||||||
// getResponseHeader('myData')可以返回我们所需的值
|
// getResponseHeader('myData')可以返回我们所需的值
|
||||||
//https://www.rails365.net/articles/cors-jin-jie-expose-headers-wu
|
//https://www.rails365.net/articles/cors-jin-jie-expose-headers-wu
|
||||||
|
console.log(ctx.request.body)
|
||||||
ctx.set("Access-Control-Expose-Headers", "myData");
|
ctx.set("Access-Control-Expose-Headers", "myData");
|
||||||
if(ctx.method == "OPTIONS"){
|
if(ctx.method == "OPTIONS"){
|
||||||
ctx.body = ""
|
ctx.body = ""
|
||||||
@@ -60,8 +63,7 @@ app.use(async (ctx,next)=>{
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const bodyParser = require('koa-bodyparser');
|
|
||||||
app.use(bodyParser());
|
|
||||||
// console.log(requter())
|
// console.log(requter())
|
||||||
app.use(requter());
|
app.use(requter());
|
||||||
app.listen(3002);
|
app.listen(3002);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ let addshop = async (ctx,next)=>{
|
|||||||
// }
|
// }
|
||||||
// JSON.stringify(a)
|
// JSON.stringify(a)
|
||||||
// console.log(ctx.request.body)
|
// console.log(ctx.request.body)
|
||||||
let { mingcheng, fenlei, maidian, jiage, huodongjia, kucun, shangjia ,xiangqing } = ctx.request.body
|
let { mingcheng, fenlei, maidian, jiage} = ctx.request.body
|
||||||
if(mingcheng == undefined){
|
if(mingcheng == undefined){
|
||||||
ctx.body = JSON.stringify({
|
ctx.body = JSON.stringify({
|
||||||
code: 1,
|
code: 1,
|
||||||
@@ -38,43 +38,30 @@ let addshop = async (ctx,next)=>{
|
|||||||
})
|
})
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
if(huodongjia == undefined){
|
if(fenlei == undefined){
|
||||||
ctx.body = JSON.stringify({
|
ctx.body = JSON.stringify({
|
||||||
code: 1,
|
code: 1,
|
||||||
msg: "活动价格不能为空"
|
msg: "分类不能为空"
|
||||||
})
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
if(kucun == undefined){
|
|
||||||
ctx.body = JSON.stringify({
|
|
||||||
code: 1,
|
|
||||||
msg: "库存不能为空"
|
|
||||||
})
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
if(shangjia == undefined){
|
|
||||||
ctx.body = JSON.stringify({
|
|
||||||
code: 1,
|
|
||||||
msg: "是否上架不能为空"
|
|
||||||
})
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
if(xiangqing == undefined){
|
|
||||||
ctx.body = JSON.stringify({
|
|
||||||
code: 1,
|
|
||||||
msg: "商品详情不能为空"
|
|
||||||
})
|
})
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ctx.body = await dbs.add("shop", ctx.request.body)
|
ctx.body = await dbs.add("shop", ctx.request.body)
|
||||||
// ctx.body="添加"
|
// ctx.body="添加"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let findshop = async (ctx, next) => {
|
let findshop = async (ctx, next) => {
|
||||||
ctx.body = await dbs.find("shop")
|
let q = {}
|
||||||
|
if(ctx.query.name){
|
||||||
|
q.mingcheng = ctx.query.name
|
||||||
}
|
}
|
||||||
|
ctx.body = await dbs.find("shop",q)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let logins = async(ctx,next)=>{
|
let logins = async(ctx,next)=>{
|
||||||
let {user , pwd} = ctx.request.body
|
let {user , pwd} = ctx.request.body
|
||||||
|
|||||||
Reference in New Issue
Block a user