diff --git a/lib/.placeholder b/.eslintignore similarity index 100% rename from lib/.placeholder rename to .eslintignore diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..d95a3244 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,7 @@ +{ + "env": { + "es6": true, + "node": true + }, + "extends": ["eslint:recommended", "plugin:prettier/recommended"] +} diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..54e01c7c --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +tidelift: npm/sockjs diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 00000000..0cd5f506 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,32 @@ +name: Node CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x, 20.x, 22.x] + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: '3.x' + architecture: 'x64' + - name: Install virtualenv + run: | + pip install virtualenv + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: npm install, build, and test + run: | + npm ci + ./scripts/test.sh + env: + CI: true diff --git a/.gitignore b/.gitignore index 5a16f43b..e041a351 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .pidfile.pid node_modules -lib/*.js *~ +sockjs-protocol diff --git a/.npmignore b/.npmignore index 28b91266..67c426ef 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,7 @@ .gitignore -lib/.placeholder -VERSION-GEN -src +.eslintrc +.eslintignore +.nvmrc node_modules +examples *~ diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..e1fcd1ea --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +lts/erbium diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..11cd494a --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "printWidth": 100, + "singleQuote": true, + "trailingComma": "none" +} diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 00000000..5d81e5dd --- /dev/null +++ b/AUTHORS @@ -0,0 +1,8 @@ +# This is the list of sockjs authors for copyright purposes. +# +# This does not necessarily list everyone who has contributed code, since in +# some cases, their employer may be the copyright holder. To see the full list +# of contributors, see the revision history in source control. +Bryce Kahle +Marek Majkowski +VMWare diff --git a/Changelog b/CHANGELOG.md similarity index 71% rename from Changelog rename to CHANGELOG.md index 71d0f723..330054da 100644 --- a/Changelog +++ b/CHANGELOG.md @@ -1,3 +1,72 @@ +# Unreleased + +## **BREAKING CHANGES** + * `installHandlers(server, options)` renamed to `attach(server)` and only takes a single argument. + This means you cannot use the same SockJS server installed at multiple prefixes. + In practice this was confusing and not common. + * `websocket` option is deprecated, but still respected. Please use the new `transports` option. + * Node.js `>= 6.5.0` is required. + +## Other Fixes/Changes + * Convert from coffeescript to ES6. + * Update minimum Node.js version to 6.X. + * Update SockJSConnection implementation to be compatible with latest Node.js streams. + * SockJSConnection properties `readable` and `writable` have been removed. These are used internally by Node.js streams. + * Remove `console.log` logging by default. + * Remove usage of exceptions for flow control. + * Add `debug` logs for easier troubleshooting. + * Added `transports` option to allow selection of specific transports. + * Added `detach(server)` function to remove SockJS from a HTTP server instance. + * Update dependencies. + * Examples have been updated to use latest versions of libraries. + + +0.3.19 +====== + + * Update `node-uuid` version #224 + * Add `disable_cors` option to prevent CORS headers from being added to responses #218 + * Add `dnt` header to whitelist #212 + * Add `x-forwarded-host` and `x-forwarded-port` headers to whitelist #208 + * Update `sockjs_url` default to latest 1.x target #223 + * Updated hapi.js example #216 + +0.3.18 +====== + + * Change to using `res.statusCode` instead of manual parsing of `res._header` #213 + * Update sockjs-protocol filename in README #203 + +0.3.17 +====== + + * Fix usage of undefined `session` in `heartbeat_timeout` #179 + +0.3.16 +====== + + * Fix CORS response for null origin #177 + * Add websocket ping-pong and close if no response #129, #162, #169 + * Update sockjs-client version in examples #182 + * Add koa example #180 + * Disable raw websocket endpoint when websocket = false #183 + * Upgrade to faye-websocket 0.10.0 and use proper close code + * When connection is aborted, don't delay the teardown + * Forward additional headers #188 + * Add `no-transform` to Cache-Control headers #189 + * Update documentation about heartbeats #192 + + +0.3.15 +====== + + * Remove usage of naked '@' function params to be compatible with coffeescript 1.9.0 #175 + +0.3.14 +====== + + * Re-publish to npm because of build issue in 0.3.13 + 0.3.13 ====== diff --git a/COPYING b/COPYING deleted file mode 100644 index 3a33d194..00000000 --- a/COPYING +++ /dev/null @@ -1,6 +0,0 @@ -Parts of the code are derived from various open source projects. - -For code derived from Socket.IO by Guillermo Rauch see -https://github.com/LearnBoost/socket.io/tree/0.6.17#readme. - -All other code is released on MIT license, see LICENSE. diff --git a/LICENSE b/LICENSE index c619778a..32cc4e64 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (C) 2011 VMware, Inc. +Copyright (c) 2011-2019 The sockjs Authors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile deleted file mode 100644 index 7d39a949..00000000 --- a/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -.PHONY: all serve clean - -COFFEE:=./node_modules/.bin/coffee - -#### General - -all: build - -build: src/*coffee - @$(COFFEE) -v > /dev/null - $(COFFEE) -o lib/ -c src/*.coffee - -clean: - rm -f lib/*.js - - -#### Testing - -test_server: build - node tests/test_server/server.js - -serve: - @if [ -e .pidfile.pid ]; then \ - kill `cat .pidfile.pid`; \ - rm .pidfile.pid; \ - fi - - @while [ 1 ]; do \ - make build; \ - echo " [*] Running http server"; \ - make test_server & \ - SRVPID=$$!; \ - echo $$SRVPID > .pidfile.pid; \ - echo " [*] Server pid: $$SRVPID"; \ - inotifywait -r -q -e modify .; \ - kill `cat .pidfile.pid`; \ - rm -f .pidfile.pid; \ - sleep 0.1; \ - done - -#### Release process -# 1) commit everything -# 2) amend version in package.json -# 3) run 'make tag' and run suggested 'git push' variants -# 4) run 'npm publish' - -RVER:=$(shell grep "version" package.json|tr '\t"' ' \t'|cut -f 4) -VER:=$(shell ./VERSION-GEN) - -.PHONY: tag -tag: all - git commit $(TAG_OPTS) package.json Changelog -m "Release $(RVER)" - git tag v$(RVER) -m "Release $(RVER)" - @echo ' [*] Now run' - @echo 'git push; git push --tag' diff --git a/README.md b/README.md index 3ae3870b..fbd67b04 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,14 @@ -[](http://badge.fury.io/js/sockjs) +# SockJS-node -SockJS family: +[](https://www.npmjs.com/package/sockjs)[](https://david-dm.org/sockjs/sockjs-node) + +# SockJS for enterprise + +Available as part of the Tidelift Subscription. + +The maintainers of SockJS and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-sockjs?utm_source=npm-sockjs&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) + +# SockJS family * [SockJS-client](https://github.com/sockjs/sockjs-client) JavaScript client library * [SockJS-node](https://github.com/sockjs/sockjs-node) Node.js server @@ -20,9 +28,12 @@ Work in progress: * [wai-SockJS](https://github.com/Palmik/wai-sockjs) * [SockJS-perl](https://github.com/vti/sockjs-perl) * [SockJS-go](https://github.com/igm/sockjs-go/) + * [actix/sockjs](https://github.com/actix/sockjs) for Rust + +⚠️️ **ATTENTION** This is pre-release documentation. The documentation for the +latest stable release is at: https://github.com/sockjs/sockjs-node/tree/v0.3.19 ️⚠️ -What is SockJS? -=============== +# What is SockJS? SockJS is a JavaScript library (for browsers) that provides a WebSocket-like object. SockJS gives you a coherent, cross-browser, Javascript API @@ -31,12 +42,10 @@ channel between the browser and the web server, with WebSockets or without. This necessitates the use of a server, which this is one version of, for Node.js. -SockJS-node server -================== +# SockJS-node server SockJS-node is a Node.js server side counterpart of -[SockJS-client browser library](https://github.com/sockjs/sockjs-client) -written in CoffeeScript. +[SockJS-client browser library](https://github.com/sockjs/sockjs-client). To install `sockjs-node` run: @@ -45,24 +54,24 @@ To install `sockjs-node` run: A simplified echo SockJS server could look more or less like: ```javascript -var http = require('http'); -var sockjs = require('sockjs'); +const http = require('http'); +const sockjs = require('sockjs'); -var echo = sockjs.createServer({ sockjs_url: 'http://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js' }); +const echo = sockjs.createServer({ prefix:'/echo' }); echo.on('connection', function(conn) { - conn.on('data', function(message) { - conn.write(message); - }); - conn.on('close', function() {}); + conn.on('data', function(message) { + conn.write(message); + }); + conn.on('close', function() {}); }); -var server = http.createServer(); -echo.installHandlers(server, {prefix:'/echo'}); +const server = http.createServer(); +echo.attach(server); server.listen(9999, '0.0.0.0'); ``` (Take look at -[examples](https://github.com/sockjs/sockjs-node/tree/master/examples/echo) +[examples](https://github.com/sockjs/sockjs-node/tree/main/examples/echo) directory for a complete version.) Subscribe to @@ -70,21 +79,20 @@ Subscribe to discussions and support. -SockJS-node API ---------------- +# SockJS-node API -The API design is based on the common Node API's like -[Streams API](http://nodejs.org/docs/v0.5.8/api/streams.html) or -[Http.Server API](http://nodejs.org/docs/v0.5.8/api/http.html#http.Server). +The API design is based on common Node APIs like the +[Streams API](https://nodejs.org/api/stream.html) or the +[Http.Server API](https://nodejs.org/api/http.html#http_class_http_server). -### Server class +## Server class SockJS module is generating a `Server` class, similar to -[Node.js http.createServer](http://nodejs.org/docs/v0.5.8/api/http.html#http.createServer) +[Node.js http.createServer](https://nodejs.org/api/http.html#http_http_createserver_requestlistener) module. ```javascript -var sockjs_server = sockjs.createServer(options); +const sockjs_server = sockjs.createServer(options); ``` Where `options` is a hash which can contain: @@ -99,7 +107,7 @@ Where `options` is a hash which can contain: domain local to the SockJS server. This iframe also does need to load SockJS javascript client library, and this option lets you specify its url (if you're unsure, point it to - + the latest minified SockJS client release, this is the default). You must explicitly specify this url on the server side for security reasons - we don't want the possibility of running any foreign @@ -123,10 +131,10 @@ Where `options` is a hash which can contain: streaming and will make streaming transports to behave like polling transports. The default value is 128K. -