ํ๋ก์ ํธ
GitHub์์ ๋ณด๊ธฐ
tinyhttp/tinyws
์๊ฐ
๐ก Node.js์ฉ ๊ฒฝ๋ WebSocket ๋ฏธ๋ค์จ์ด์ ๋๋ค.
์น ๋ฐ ์ฑ ๊ฐ๋ฐWhat you can do
- Small size (498B)
- Easy to use (only req.ws and nothing else)
- Framework-agnostic (works with tinyhttp, express etc)
- Written in TypeScript
์ธก์ ๋ ์คํ ์ฆ๊ฐ
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- ๊ธฐ๋ก ์์ง ์ค
์๋ก ๊ฒน์น๋ ๊ธฐ๊ฐ์ ์์ฆ๊ฐ๋์ด๋ฉฐ ์ผ๋ณ ํฉ๊ณ๊ฐ ์๋๋๋ค. ์ธก์ ๊ฐ์ด ์์ผ๋ฉด ๋น์ ๋ก๋๋ค. ์คํ๋ ๊ด์ฌ๋๋ฅผ ๋ํ๋ด๋ฉฐ ํ์ง์ ๋ณด์ฅํ์ง ์์ต๋๋ค.
README.md
Originaltinyws is a WebSocket middleware for Node.js based on ws, inspired by koa-easy-ws.
Check the chat example out to get familiar with tinyws.
Features
- Small size (498B)
- Easy to use (only
req.wsand nothing else) - Framework-agnostic (works with tinyhttp, express etc)
- Written in TypeScript
- Pure ESM
Why not express-ws?
because express-ws is...
- Abandoned since 2018 ๐
- Doesn't come with types out of the box (have to install
@types/express-ws) - Not compatible with tinyhttp and polka
- Buggy as hell
- Doesn't have tests
Install
pnpm i ws tinyws
Example
import { App, Request } from '@tinyhttp/app'
import { tinyws, TinyWSRequest } from 'tinyws'
const app = new App<Request & TinyWSRequest>()
app.use('/ws', async (req, res) => {
if (req.ws) {
const ws = await req.ws()
return ws.send('hello there')
} else {
res.send('Hello from HTTP!')
}
})
const server = app.listen(3000)
tinyws(app, server)
Restricting WebSocket to specific paths
You can restrict WebSocket handling to specific paths using the paths option:
// Single path
tinyws(app, server, { paths: '/ws' })
// Multiple paths
tinyws(app, server, { paths: ['/ws', '/socket'] })
See examples for express and polka integration.
๊ด๋ จ ํ๋ก์ ํธ ์ดํด๋ณด๊ธฐ
๋ถ๋ฌ์ค๋ ์คโฆ