Add WebSocket, HTTPS, and Bankai middleware to single HTTPS server

parent 04738fff
Pipeline #782 canceled with stages
require('./to-include.js')
\ No newline at end of file
require('./to-include.js')
const socket = new WebSocket('wss://localhost/echo')
socket.onopen = event => {
console.log('Socket open.')
setInterval(() => {
socket.send('Hello, there!')
}, 1000)
}
socket.onmessage = event => {
console.log(`Received: ${event.data}`)
}
const bankai = require('bankai/http')
const express = require('express')
const httpsServer = require('@ind.ie/https-server')
const expressWebSocket = require('express-ws')
const path = require('path')
const websocketRouter = express.Router()
const compiler = bankai(path.join(__dirname, 'client.js'))
const app = express()
const server = httpsServer.createServer({}, app)
// TODO: Add WebSocket route.
// Websocket routes go here
const webSocketServer = expressWebSocket(app, server, {
perMessageDeflate: false
})
// Add web socket routes.
app.ws('/echo', (webSocket, request) => {
webSocket.on('message', message => {
console.log('Got web socket request to echo ', message)
webSocket.send(message)
})
})
// Server-side routes go here.
app.get('/hello', (request, response) => {
......@@ -16,11 +32,10 @@ app.get('/hello', (request, response) => {
response.end('<!doctype html><html lang=\'en\'><head><meta charset=\'utf-8\'/><title>Hello</title></head><body>Hello!</body></html>')
})
// Finally, use Bankai.
app.use(compiler)
const server = httpsServer.createServer({}, app)
server.listen(443, () => {
console.log('Listening on port 443.')
})
{
"name": "use-bankai",
"name": "bankai-express",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
......@@ -282,6 +282,11 @@
"resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.1.tgz",
"integrity": "sha1-GdOGodntxufByF04iu28xW0zYC0="
},
"async-limiter": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
},
"async-reduce": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/async-reduce/-/async-reduce-0.0.1.tgz",
......@@ -2650,6 +2655,14 @@
}
}
},
"express-ws": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/express-ws/-/express-ws-4.0.0.tgz",
"integrity": "sha512-KEyUw8AwRET2iFjFsI1EJQrJ/fHeGiJtgpYgEWG3yDv4l/To/m3a2GaYfeGyB3lsWdvbesjF5XCMx+SVBgAAYw==",
"requires": {
"ws": "^5.2.0"
}
},
"extend": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/extend/-/extend-1.3.0.tgz",
......@@ -6857,6 +6870,14 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"ws": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz",
"integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==",
"requires": {
"async-limiter": "~1.0.0"
}
},
"xtend": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
......
......@@ -11,6 +11,7 @@
"dependencies": {
"@ind.ie/https-server": "^2.0.0",
"bankai": "git+https://aral@github.com/aral/bankai.git#hypha",
"express": "^4.16.4"
"express": "^4.16.4",
"express-ws": "^4.0.0"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment