Code Monkey home page Code Monkey logo

koa-websocket's Introduction

SocketIO

业务介绍

  • 用户扫码调用api接口,修改订单状态,并把订单信息发送给所有websocket客户端
  • (注1:http接口和websocket没有加权限验证,因为就只能改个订单状态和获取订单信息,懒得加权限验证了)
  • (注2:正常情况是需要加入消息队列,websocket客户端发送指令,不断消费订单信息,但是因为就一个用户用,所以这里一切从简,只缓存所有socket客户端连接,直接发送消息,就是这么简单粗暴)

Running Start

npm install
npm start

open in browser

http://127.0.0.1:3000/

启动方式

最简单启动方式

node bin/run

最常用的集成nodemon的方式,代码变动会自动重载(其实就是nodemon去执行bin/run)

npm start

支持pm2部署

 #npm run pm2
 pm2 start bin/run 

支持koa2的3种中间件写法

Koa 2是一个 middleware framework, 它提供了 3 种不同类型的中间件写法

  • common function
  • async function(新增)
  • generatorFunction

详见koa 2的文档

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.