https://github.com/scalajs-io/express-ws
WebSocket endpoints for Express applications
https://github.com/scalajs-io/express-ws
express expressjs node nodejs npm npm-package websocket
Last synced: 4 months ago
JSON representation
WebSocket endpoints for Express applications
- Host: GitHub
- URL: https://github.com/scalajs-io/express-ws
- Owner: scalajs-io
- License: apache-2.0
- Created: 2017-02-12T00:14:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T23:08:35.000Z (about 6 years ago)
- Last Synced: 2025-01-17T22:42:39.033Z (5 months ago)
- Topics: express, expressjs, node, nodejs, npm, npm-package, websocket
- Language: Scala
- Size: 18.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ExpressWS API for Scala.js
================================
[express-ws](https://www.npmjs.com/package/express-ws) - WebSocket endpoints for [Express](https://github.com/scalajs-io/express) applications.### Description
WebSocket endpoints for [Express](https://github.com/scalajs-io/express) applications.
Lets you define WebSocket endpoints like any other type of route,
and applies regular Express midddleware like for anything else.Version 2.0 of this library contains a breaking change.
Please make sure to read [CHANGELOG.md](https://github.com/HenningM/express-ws/blob/master/CHANGELOG.md) before upgrading.### Build Dependencies
* [SBT v1.2.x](http://www.scala-sbt.org/download.html)
### Build/publish the SDK locally
```bash
$ sbt clean publish-local
```### Running the tests
Before running the tests the first time, you must ensure the npm packages are installed:
```bash
$ npm install
```Then you can run the tests:
```bash
$ sbt test
```### Examples
```scala
import io.scalajs.npm.express._
import io.scalajs.npm.expressws._
import io.scalajs.util.JSONHelper._
import io.scalajs.util.ScalaJsHelper._
import scala.scalajs.jsval app = Express().withWsRouting
val expressWs = ExpressWS(app)app.use((req: Request, res: Response, next: js.Function0[Unit]) => {
println("middleware")
req.dynamic.testing = "testing"
next()
})app.get("/", (ws: WS, req: Request, res: Response, next: js.Function0[Unit]) => {
println(s"get route ${req.dynamic.testing}")
res.end()
})app.ws("/", (ws: WS, req: Request) => {
ws.onMessage { msg =>
println(msg.toJson)
}
println(s"socket: ${req.dynamic.testing}")
})app.listen(3000)
```### Artifacts and Resolvers
To add the `ExpressWS` binding to your project, add the following to your build.sbt:
```sbt
libraryDependencies += "io.scalajs.npm" %%% "express-ws" % "0.5.0"
```Optionally, you may add the Sonatype Repository resolver:
```sbt
resolvers += Resolver.sonatypeRepo("releases")
```