npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-yuekao

v1.0.1

Published

[![NPM version][npm-image]][npm-url] [![Build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url] [![Dependency Status][david-image]][david-url] [![License][license-image]][license-url] [![Downloads][downloads-image]

Downloads

2

Readme

koa-static

NPM version Build status Test coverage Dependency Status License Downloads

Koa static file serving middleware, wrapper for koa-send.

Installation

$ npm install koa-static

API

const Koa = require('koa');
const app = new Koa();
app.use(require('koa-static')(root, opts));
  • root root directory string. nothing above this root directory can be served
  • opts options object.

Options




router.post('/user/logon',indexController.Logon)
router.post('/user/sendcode',indexController.SendCode)
router.post('/user/login',indexController.Login)
router.get('/user/getUser', indexController.GetUser);

router.post('/order/add',userController.AddOrder)
router.get('/order/show',userController.OrderShow)
router.delete("/order/delete",userController.DeleteOrder)
router.post("/order/again",userController.AgainByShop)
router.put("/order/update",userController.UpdateStatus)


  • maxage Browser cache max-age in milliseconds. defaults to 0
  • hidden Allow transfer of hidden files. defaults to false
  • index 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.
  • setHeaders Function to set custom headers on response.
  • 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)

Example



const ChaeckPhone=async(params)=>{
    var sql=` select * from userinfo where phone='${params.phone}' `
    return await query(sql)
}

const AddUser=async(params)=>{
    var newpassword=md5(params.password)
    var sql=` insert into userinfo (account,password,phone) values
    ('${params.account}','${newpassword}','${params.phone}') `
    return await query(sql)
}


See also

Options

  • maxage Browser cache max-age in milliseconds. defaults to 0
  • hidden Allow transfer of hidden files. defaults to false
  • index 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.
  • setHeaders Function to set custom headers on response.
  • 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)

Example



const ChaeckPhone = async (params) => {
    var sql = ` select * from userinfo where account='${params.account}' or phone='${params.phone}' `
    return await query(sql)
}



const AddUser = async (params) => {
    var newpassword = md5(params.password)
    var sql = ` insert into userinfo (account,password,phone)values 
    ('${params.account}','${newpassword}','${params.phone}') `
    return await query(sql)
}


const AddOrder = async (params) => {
    var sql1 = ` select a.*,a.count*b.price zprice from car a join shop b on a.shopid=b.id where a.id in (${params.ids}) `
    var caedata = await query(sql1)
    if (caedata.length == 0) {
        return {
            affectedRows: 0
        }
    }
    var sql2 = ` insert into orders (shopid,zprice,userid,ordercode,cretime,status) values`
    for (let i = 0; i < caedata.length; i++) {
        var shopid = caedata[i].shopid;
        var userid = caedata[i].userid;
        var zprice = caedata[i].zprice;
        var ordercode = Math.random().toFixed(10).slice(-10)
        var cretime = moment().format('YYYY-MM-DD HH:mm:ss');

        sql2 += `('${shopid}','${zprice}','${userid}','${ordercode}','${cretime}','0'),`
    }
    sql2 = sql2.substring(0, sql2.length - 1)
    var orderdata = await query(sql2)
    if (orderdata.affectedRows > 0) {
        var sql3 = ` delete from car where id in (${params.ids})`
        return await query(sql3)
    } else {
        return {
            affectedRows: 0
        }
    }
}


const OrderShow = async (params) => {
    var page = params.page;
    var size = params.size;
    var sql = ` select a.*,b.shopname,b.price shopprice from orders a 
    join shop b on a.shopid=b.id where 1=1`
    if (params.shopname) {
        sql += ` and b.shopname like '%${params.shopname}%'`
    }
    if (params.status != -1 && params.status != undefined) {
        sql += ` and a.status='${params.status}' `
    }
    var zcount = (await query(sql)).length;
    sql += ` limit ${(page-1)*size},${size} `
    var res = await query(sql)
    return {res,zcount}
}


const DeleteOrder = async(params)=>{
    var sql=` delete from orders where status='4' and id='${params.id}' `
    return await query(sql2)
}

const AgainByShop=async(params)=>{
    var sql1=` select * from orders where id='${params.id}' `
    var orderdata=await query(sql1);
    var createtime = moment().format('YYYY-MM-DD HH:mm:ss');
    var ordercode = Math.random().toFixed(10).slice(-10)
    var sql2=` insert into orders (ordercode,shopid,price,status,userid,count,createtime) values
    ('${ordercode}','${orderdata[0].shopid}','${orderdata[0].price}','0','${orderdata[0].userid}','${orderdata[0].count}','${createtime}')
    `
    return await query(sql2)
}

const UpdateStatus=async(params)=>{
    var status=0;
    if(params.status==0){
        status=1
    }else if(params.status==1){
        status=2
    }else if(params.status==2){
        status=3
    }else if(params.status==3){
        status=4
    }else{
        return {affectedRows:0}
    }
    var sql=` update orders set status=${status} where id='${params.id}' `
    return await query(sql)
}




See also

Options

  • maxage Browser cache max-age in milliseconds. defaults to 0
  • hidden Allow transfer of hidden files. defaults to false
  • index 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.
  • setHeaders Function to set custom headers on response.
  • 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)

Example



const AddOrder = async (ctx) => {
    var res = await userServics.AddOrder(ctx.request.body);
    if (res.affectedRows > 0) {
        return ctx.body = {
            code: 200,
            message: ''
        }
    } else {
        return ctx.body = {
            code: 403,
            message: ''
        }
    }

}


const OrderShow = async (ctx) => {
    ctx.request.query.userid=ctx.state.user.data.id
    var res = await userServics.OrderShow(ctx.request.query)
    if (res.res.length > 0) {
        return ctx.body = {
            code: 200,
            msg: '',
            data:res
        }
    } else {
        return ctx.body = {
            code: 403,
            msg: ''
        }
    }
}


const DeleteOrder = async (ctx) => {
    var res = await userServics.DeleteOrder(ctx.request.query)
    if (res.affectedRows > 0) {
        return ctx.body = {
            code: 200,
            msg: ''
        }
    } else {
        return ctx.body = {
            code: 403,
            msg: ''
        }
    }
}

const AgainByShop = async (ctx) => {
    var res = await userServics.AgainByShop(ctx.request.body)
    if (res.affectedRows > 0) {
        return ctx.body = {
            code: 200,
            msg: ''
        }
    } else {
        return ctx.body = {
            code: 403,
            msg: ''
        }
    }
}

const UpdateStatus = async (ctx) => {
    var res = await userServics.UpdateStatus(ctx.request.body)
    if (res.affectedRows > 0) {
        return ctx.body = {
            code: 200,
            msg: ''
        }
    } else {
        return ctx.body = {
            code: 403,
            msg: ''
        }
    }
}


See also

Options

  • maxage Browser cache max-age in milliseconds. defaults to 0

  • hidden Allow transfer of hidden files. defaults to false

  • index 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.

  • setHeaders Function to set custom headers on response.

  • 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)

Example





const Logon = async(ctx)=>{
    var res = await indexServics.ChaeckPhone(ctx.request.body);
    if(res.length>0){
        return ctx.body={
            code:403,
            message:''
        }
    }
    var res1 = await indexServics.AddUser(ctx.request.body);
    if(res1.affectedRows>0){
        return ctx.body={
            code:200,
            message:''
        }
    }else{
        return ctx.body={
            code:403,
            message:''
        }
    }
}
const SendCode = async(ctx)=>{
    var phone = ctx.request.body.phone
    if(!phone){
        return ctx.body={
            code:403,
            message:''
        }
    }
    var checephone= /^1[3-9]\d{9}$/
    if(!checephone){
        return cyx.body={
            code:403,
            message:''
        }
    }
    var rediscode = await redis.get(phone)
    if(rediscode==null){
        var code = Math.random().toFixed(6).slice(-6)
        await redis.setex(phone,60,code);
        return ctx.body={
            code:200,
            message:'',
            data:code
        }
    }else{
        return ctx.body={
            code:403,
            message:''
        }
    }
}

const Login = async(ctx)=>{
    var res = await indexServics.ChaeckPhone(ctx.request.body)
    if(res.length==0){
        return ctx.body={
            code:403,
            message:''
        }
    }
    var rediscode = await redis.get(ctx.request.body.phone)
    if(rediscode==ctx.request.body.code){
        var token = await jwt.signtoken(res[0])
        return ctx.body={
            code:200,
            message:'',
            data:'Bearer '+token
        }
    }else{
        return ctx.body={
            code:403,
            message:''
        }
    }
}

const GetUser=(ctx)=>{
    var userinfo=ctx.state.user.data;
    return ctx.body = {
        code: 200,
        message: "",
        data:[userinfo]
    }

}


See also

CCCCCCAAAAARRRR


<body>
    <div>
        <span>   </span><input type="text" id="phone">
        <span>   </span><input type="text" id="code">
        <input type="button" value="  " onclick="SendCode()">
        <input type="button" value="   " onclick="Login()">
    </div>
    <div id="data"></div>
</body>

<script>
    const SendCode = async()=>{
        var data={
            phone:document.getElementById("phone").value
        }
        var res = await request.post('/user/sendcode',data);
        if(res.data.code==200){
            alert(res.data.data)
        }else{
            alert(res.data.message)
        }
    }
    const Login = async()=>{
        var data ={
            phone:document.getElementById('phone').value,
            code:document.getElementById('code').value
        }
        var res = await request.post('/user/login',data)
        if(res.data.code==200){
            localStorage.setItem('token',res.data.data)
            location.href='/myWeb/Add.html';
            
        }else{
            alert(res.data.message)
        }
    }

   
</script>
</html>

See also

LOGIN



<body>
    <input type="text" id="type" value="-1" hidden>
    <div>
        <span>   </span><input type="text" id="shopname">
        <input type="button" value="  " onclick="Query()">
    </div>
    <div>
        <input type="button" value="   " onclick="Type(-1)">
        <input type="button" value="   " onclick="Type(0)">
        <input type="button" value="   " onclick="Type(1)">
        <input type="button" value="   " onclick="Type(2)">
        <input type="button" value="   " onclick="Type(3)">
        <input type="button" value="   " onclick="Type(4)">
    </div>
    <table style="text-align: center;">
        <thead>
            <tr>
                <td>   </td>
                <td>   </td>
                <td>   </td>
                <td>   </td>
                <td>   </td>
                <td>   </td>
                <td>   </td>
                <td>   </td>
            </tr>
        </thead>
        <tbody id="data"></tbody>
    </table>
    <div>
        <input type="button" value="  " onclick="Page(true)">
        <input type="button" value="  " onclick="Page(false)">
    </div>
</body>

<script>
    var page = 1;
    var size = 3;
    var zcount = 0
    var OrderShow = async () => {
        var data = {
            page,
            size,
            shopname: document.getElementById('shopname').value,
            status: document.getElementById('type').value
        }
        var res = await request.get("/order/show", {
            params: data
        })
        if (res.data.code == 200) {
            document.getElementById('data').innerHTML = res.data.data.res.map((i) => {
                return `
                <tr>
                    <td>${i.ordercode}</td>
                <td>${i.shopname}</td>
                <td>${i.shopprice}</td>
                <td>${i.zprice}</td>
                    <td>${i.status == 0 ? "  " : i.status == 1 ? "  " : i.status == 2 ? "  " : i.status == 3 ? "  " : "   "}</td>
                    <td>${i.cretime.substring(0,10)}</td>
                    <td>
                        <input type="button" value="  " onclick="Details(${i.shopid})">
                        <input type="button" value="  " onclick="DeleteOrder(${i.id})">
                        <input type="button" value="  " onclick="Again(${i.id},${i.status})">
                        <input type="button" value="  " onclick="UpdateStatus(${i.id},${i.status})">
                        
                    </td>
                </tr>
                `
            }).join('')
            zcount = res.data.data.zcount
        } 
    }
    OrderShow()


    const Query = () => {
        page = 1;
        OrderShow()
    }
    const Page = (data) => {
        if (data) {
            if (page == 1) {
                return alert('   ')
            } else {
                page = page - 1
            }
        } else {
            if (page == Math.ceil(zcount / size)) {
                return alert('   ')
            } else {
                page = page + 1
            }
        }
        OrderShow()
    }
    const Type = (data) => {
        document.getElementById('type').value = data
        OrderShow()
    }

    const Details = (id) => {
        location.href = '/myWeb/Details.html?iid' + id
    }

    const DeleteOrder = async (id) => {
        var res = await request.delete('/order/delete', {
            params: {
                id
            }
        })
        if (res.data.code == 200) {
            OrderShow()
        } else {
            alert(res.data.message)
        }
    }

    const Again = async (id, status) => {
        if (status != 4) {
            return alert('   ')
        }
        var res = await request.post('/order/again', {
            id
        })
        if (res.data.code == 200) {
            OrderShow()
        } else {
            alert(res.data.message)
        }
    }

    const UpdateStatus = async (id, status) => {
        if (status == 4) {
            return alert('   ')
        }
        var res = await request.put('/order/update', {
            id,
            status
        })
        if (res.data.code == 200) {
            OrderShow()
        } else {
            return alert('   ')
        }
    }
</script>

</html>

See also

License

MIT