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)
|
||||
// import requter from "./bin/router"
|
||||
const app = new Koa();
|
||||
const bodyParser = require('koa-bodyparser');
|
||||
app.use(bodyParser());
|
||||
app.use(async (ctx, next) => {
|
||||
// 允许来自所有域名请求
|
||||
ctx.set("Access-Control-Allow-Origin", "*");
|
||||
@@ -40,6 +42,7 @@ app.use(async (ctx, next) => {
|
||||
// 需要获取其他字段时,使用Access-Control-Expose-Headers,
|
||||
// getResponseHeader('myData')可以返回我们所需的值
|
||||
//https://www.rails365.net/articles/cors-jin-jie-expose-headers-wu
|
||||
console.log(ctx.request.body)
|
||||
ctx.set("Access-Control-Expose-Headers", "myData");
|
||||
if(ctx.method == "OPTIONS"){
|
||||
ctx.body = ""
|
||||
@@ -60,8 +63,7 @@ app.use(async (ctx,next)=>{
|
||||
});
|
||||
|
||||
|
||||
const bodyParser = require('koa-bodyparser');
|
||||
app.use(bodyParser());
|
||||
|
||||
// console.log(requter())
|
||||
app.use(requter());
|
||||
app.listen(3002);
|
||||
|
||||
@@ -16,7 +16,7 @@ let addshop = async (ctx,next)=>{
|
||||
// }
|
||||
// JSON.stringify(a)
|
||||
// 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){
|
||||
ctx.body = JSON.stringify({
|
||||
code: 1,
|
||||
@@ -38,34 +38,15 @@ let addshop = async (ctx,next)=>{
|
||||
})
|
||||
return ;
|
||||
}
|
||||
if(huodongjia == undefined){
|
||||
if(fenlei == undefined){
|
||||
ctx.body = JSON.stringify({
|
||||
code: 1,
|
||||
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: "商品详情不能为空"
|
||||
msg: "分类不能为空"
|
||||
})
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ctx.body = await dbs.add("shop", ctx.request.body)
|
||||
// ctx.body="添加"
|
||||
@@ -73,9 +54,15 @@ let addshop = 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 {user , pwd} = ctx.request.body
|
||||
console.log(123)
|
||||
|
||||
Reference in New Issue
Block a user