0.4.0 • Published 1 month ago

@reneos/server v0.4.0

Weekly downloads
101
License
MIT
Repository
github
Last release
1 month ago

Simple Servers

This package is designed to quickly launch lightweight servers (http or websocket).

npm https://www.npmjs.com/package/@reneos/server

Install

npm i @reneos/server

Usage WebSocket

WsServer - Wrapper for ws package - added convenient pre-authorization support, sub-protocol implementation, network callbacks implemented

import { WsServer } from "@reneos/server"

function Parser(msg, uid){
    if(msg.id){//Message recommends an answer
        _server.sendTo({
            target:0,
			type: 0,
			on: msg.id,
			data: {value:'ANY'}
		}, [userId])
    }
}

/**
	* 
	* @param {*} request 
	* @param {*} socket 
	* @param {*} head 
	* @returns connection ID if allow or NULL if not allow
	*/
function Verify(request, socket, head){
    return request.headers['user'].id
}

const _server = new WsServer()
_server.on("connect", (uid, ws) => {
	console.log(`Connection  (${uid}) connected : (${_server.count} connections)`)
})
_server.on('disconnect', (uid, code, reason) => {
	console.log(`Connection  (${uid}) disconnected : (${_server.count} connections)`)
})
_server.on('upgrade', () => { /*console.log('upgrade')*/ })
_server.on('headers', () => { /*console.log('headers')*/ })
_server.on("message", Parser)
_server.start({port:12345},Verify)

Usage WebServer

See usage examples in the /examples/ folder

0.4.0

1 month ago

0.3.8

2 months ago

0.3.9

2 months ago

0.3.7

2 months ago

0.3.6

2 months ago

0.3.4

3 months ago

0.3.3

3 months ago

0.3.0

4 months ago

0.3.2

4 months ago

0.3.1

4 months ago

0.2.6

4 months ago

0.2.8

4 months ago

0.2.1

6 months ago

0.1.7

6 months ago

0.2.3

6 months ago

0.2.2

6 months ago

0.2.5

5 months ago

0.2.4

6 months ago

0.1.6

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.5

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.0.25

3 years ago

0.0.30

3 years ago

0.0.31

3 years ago

0.0.26

3 years ago

0.0.27

3 years ago

0.0.28

3 years ago

0.0.29

3 years ago

0.0.23

3 years ago

0.0.24

3 years ago

0.1.20

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.19

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.15

3 years ago

0.0.16

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago