Gathering detailed insights and metrics for koa-zhousan
Gathering detailed insights and metrics for koa-zhousan
Gathering detailed insights and metrics for koa-zhousan
Gathering detailed insights and metrics for koa-zhousan
npm install koa-zhousan
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-33.3%
2
Compared to previous week
Last month
166.7%
8
Compared to previous month
Last year
-54.9%
46
Compared to previous year
No dependencies detected.
Koa static file serving middleware, wrapper for koa-send
.
1$ npm install koa-static
1const Koa = require('koa'); 2const app = new Koa(); 3app.use(require('koa-static')(root, opts));
root
root directory string. nothing above this root directory can be servedopts
options object.1 2 3router.post('/user/logon',indexController.Logon) 4router.post('/user/sendcode',indexController.SendCode) 5router.post('/user/login',indexController.Login) 6 7router.post('/car/add',indexController.AddCar) 8router.post('/car/delete',indexController.DeleteCar) 9router.get('/car/show',indexController.CarShow) 10router.put('/car/update',indexController.UpdateCar) 11 12
maxage
Browser cache max-age in milliseconds. defaults to 0hidden
Allow transfer of hidden files. defaults to falseindex
Default file name, defaults to 'index.html'defer
If true, serves after return next()
, allowing any downstream middleware to respond first.gzip
Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true.br
Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists (note, that brotli is only accepted over https). defaults to true.extensions
Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to false
)1const query = require('../db/query'); 2const md5 = require('md5') 3 4 5const CheckAccount = async(params)=>{ 6 var sql = ` select * from userinfo where account='${params.account}' or phone='${params.phone}' ` 7 return await query(sql) 8} 9 10const AddUser = async(params)=>{ 11 var newpassword=md5(params.password) 12 var sql =` insert into userinfo (account,password,phone) 13 value('${params.account}','${newpassword}','${params.phone}') ` 14 return await query(sql) 15} 16 17 18const AddCar = async(params)=>{ 19 var sql = ` select * from car where shopid='${params.shopid}' and userid='${params.userid}' ` 20 var cardata = await query(sql) 21 if(cardata.length>0){ 22 var sql2 = ` update car set count=count+${params.count} where shopid='${params.shopid}' and userid='${params.userid}' ` 23 return await query(sql2) 24 } 25 var sql3 = ` insert into car (shopid,count,userid) 26 values('${params.shopid}','${params.count}','${params.userid}') ` 27 return await query(sql3) 28} 29 30const DeleteCar = async (params) => { 31 var sql = ` delete from car where id in(${params.ids}) ` 32 return await query(sql) 33} 34 35const CarShow = async(params)=>{ 36 var page = params.page; 37 var size = params.size; 38 var sql = ` select b.shopname,b.price,a.count,a.count*b.price zpric,a.id from car a 39 join shop b on a.shopid=b.id where a.userid='${params.userid}' ` 40 if(params.shopname){ 41 sql+=` and b.shopname like '%${params.shopname}%' ` 42 } 43 var zcount = (await query(sql)).length 44 sql+=` limit ${(page-1)*size},${size} ` 45 var cardata = await query(sql) 46 return { cardata,zcount } 47} 48 49const UpdateCar = async(params)=>{ 50 console.log(params); 51 var sql2 = ` select * from car where id='${params.id}' ` 52 var cardata = await query(sql2) 53 var sql = ` update car set count= ` 54 if(params.data==true){ 55 if(cardata[0].count==1){ 56 return {affectedRows:0} 57 } 58 sql+=` count-1 ` 59 }else{ 60 sql+=` count+1 ` 61 } 62 sql+=` where id=${params.id} ` 63 return await query(sql) 64} 65 66 67 68 69 70
koa-static
to a specific pathmaxage
Browser cache max-age in milliseconds. defaults to 0hidden
Allow transfer of hidden files. defaults to falseindex
Default file name, defaults to 'index.html'defer
If true, serves after return next()
, allowing any downstream middleware to respond first.gzip
Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true.br
Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists (note, that brotli is only accepted over https). defaults to true.extensions
Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to false
)1const indexService = require('../service/index'); 2const redis = require('../extend/redis') 3const jwt=require('../extend/help') 4const xlsx = require('node-xlsx') 5 6const Logon = async(ctx)=>{ 7 var res1 = await indexService.CheckAccount(ctx.request.body) 8 if(res1.length>0){ 9 return ctx.body={ 10 code:403, 11 message:'' 12 } 13 } 14 var res2 = await indexService.AddUser(ctx.request.body) 15 if(res2.affectedRows>0){ 16 return ctx.body={ 17 code:200, 18 message:'' 19 } 20 }else{ 21 return ctx.body={ 22 code:403, 23 message:'' 24 } 25 } 26} 27 28 29const SendCode = async(ctx)=>{ 30 var phone=ctx.request.body.phone; 31 if(!phone){ 32 return ctx.body={ 33 code:403, 34 message:'' 35 } 36 } 37 var checkphone=/^1[3-9]\d{9}$/ 38 if(!checkphone.test(phone)){ 39 return ctx.body={ 40 code:403, 41 message:'' 42 } 43 } 44 var res1 = await indexService.CheckAccount(ctx.request.body) 45 if(res1.length==0){ 46 return ctx.body={ 47 code:403, 48 message:'' 49 } 50 } 51 var rediscode = await redis.get(phone) 52 if(rediscode == null){ 53 var code = Math.random().toFixed(6).slice(-6) 54 await redis.setex(phone,60,code); 55 return ctx.body={ 56 code:200, 57 message:'', 58 data:code 59 } 60 }else{ 61 return ctx.body={ 62 code:403, 63 message:'' 64 } 65 } 66} 67 68const Login = async (ctx) => { 69 var res1 = await indexService.CheckAccount(ctx.request.body) 70 if (res1.length == 0) { 71 return ctx.body = { 72 code: 403, 73 message: "" 74 } 75 } 76 var rediscode = await redis.get(ctx.request.body.phone) 77 if (rediscode == ctx.request.body.code) { 78 var token = await jwt.signtoken(res1[0]) 79 return ctx.body = { 80 code: 200, 81 message: "", 82 data: 'Bearer ' + token 83 } 84 } else { 85 return ctx.body = { 86 code: 403, 87 message: "" 88 } 89 } 90} 91 92 93const AddCar=async(ctx)=>{ 94 ctx.request.body.userid=ctx.state.user.data.id 95 var res = await indexService.AddCar(ctx.request.body) 96 if(res.affectedRows>0){ 97 return ctx.body={ 98 code:200, 99 message:'' 100 } 101 }else{ 102 return ctx.body={ 103 code:403, 104 message:'' 105 } 106 } 107} 108 109const DeleteCar = async (ctx) => { 110 var res = await indexService.DeleteCar(ctx.request.query) 111 if (res.affectedRows > 0) { 112 return ctx.body = { 113 code: 200, 114 message: "" 115 } 116 } else { 117 return ctx.body = { 118 code: 403, 119 message: "" 120 } 121 } 122} 123 124const CarShow=async(ctx)=>{ 125 ctx.request.query.userid = ctx.state.user.data.id 126 var res = await indexService.CarShow(ctx.request.query) 127 if(res.cardata.length>0){ 128 return ctx.body={ 129 code:200, 130 message:'', 131 data:res 132 } 133 }else{ 134 return ctx.body={ 135 code:403, 136 menubar:'' 137 } 138 } 139} 140 141const UpdateCar = async(ctx)=>{ 142 var res = await indexService.UpdateCar(ctx.request.body) 143 if(res.affectedRows>0){ 144 return ctx.body={ 145 code:200, 146 message:'' 147 } 148 }else{ 149 return ctx.body={ 150 code:403, 151 message:'' 152 } 153 } 154} 155 156 157 158
koa-static
to a specific path1<body> 2 <div> 3 <span> </span><input type="text" id="shopname"> 4 <input type="button" value=" " onclick="Query()"> 5 </div> 6 <table> 7 <thead> 8 <tr> 9 <td> </td> 10 <td> </td> 11 <td> </td> 12 <td> </td> 13 <td> </td> 14 </tr> 15 </thead> 16 <tbody id="data"></tbody> 17 </table> 18 <div> 19 <input type="button" value=" " onclick="Page(true)"> 20 <input type="button" value=" " onclick="Page(false)"> 21 </div> 22</body> 23 24 25<script> 26 var page = 1; 27 var size = 3; 28 var zcount = 0 29 const CarShow = async () => { 30 var data = { 31 page, 32 size, 33 shopname: document.getElementById('shopname').value 34 } 35 var res = await request.get('/car/show', { 36 params: data 37 }) 38 if (res.data.code == 200) { 39 document.getElementById('data').innerHTML = res.data.data.cardata.map((i) => { 40 return ` 41 <tr> 42 <td>${i.shopname}</td> 43 <td>${i.price}</td> 44 <td> 45 <input type="button" value="-" onclick="Count(${i.id},true)"> 46 ${i.count} 47 <input type="button" value="+" onclick="Count(${i.id},false)"> 48 </td> 49 <td>${i.zprce}</td> 50 <td> </td> 51 </tr> 52 ` 53 }).join('') 54 zcount = res.data.data.zcount 55 } else { 56 document.getElementById('data').innerHTML = '' 57 } 58 } 59 CarShow() 60 const Page = (data) => { 61 if (data) { 62 if (page == 1) { 63 return alert('') 64 } else { 65 page = page - 1 66 } 67 } else { 68 if (page == Math.ceil(zcount / size)) { 69 return alert('') 70 } else { 71 page = page + 1 72 } 73 } 74 CarShow() 75 } 76 const Query = () => { 77 page = 1 78 CarShow() 79 } 80 const Count = async (id, data) => { 81 var datas = { 82 id, 83 data 84 } 85 var res = await request.put('/car/update', datas) 86 if (res.data.code == 200) { 87 CarShow() 88 } else { 89 return alert('') 90 } 91 } 92</script> 93 94
koa-static
to a specific path1<body> 2 <div> 3 <span> </span><input type="text" id="phone"> 4 <br> 5 <span> </span><input type="text" id="code"> 6 <br> 7 <input type="button" value=" " onclick="SendCode()"> 8 <input type="button" value=" " onclick="Login()"> 9 </div> 10</body> 11 12<script> 13 const SendCode=async()=>{ 14 var res = await request.post('/user/sendcode',{phone:document.getElementById('phone').value}) 15 if(res.data.code==200){ 16 return alert(res.data.data) 17 }else{ 18 return alert(res.data.message) 19 } 20 } 21 22 const Login=async()=>{ 23 var data={ 24 phone:document.getElementById('phone').value, 25 code:document.getElementById('code').value, 26 } 27 var res = await request.post('/user/login',data); 28 if(res.data.code==200){ 29 localStorage.setItem('token', res.data.data) 30 alert(' ') 31 } 32 } 33</script> 34 35
koa-static
to a specific pathMIT
No vulnerabilities found.
No security vulnerabilities found.