📝 Added sandbox (code sketchbook)
This commit is contained in:
parent
b475595f7f
commit
b5daf18b1a
142 changed files with 100702 additions and 0 deletions
25
sandbox/express_websockets/websocketServer.js
Normal file
25
sandbox/express_websockets/websocketServer.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Taken from (does not work on its own):
|
||||
// https://scribe.rip/m/global-identity-2?redirectUrl=https%3A%2F%2Fcodeburst.io%2Fpolling-vs-sse-vs-websocket-how-to-choose-the-right-one-1859e4e13bd9
|
||||
|
||||
const express = require('express');
|
||||
const events = require('./events');
|
||||
const path = require('path');
|
||||
|
||||
const app = express();
|
||||
|
||||
const port = process.env.PORT || 5001;
|
||||
|
||||
const expressWs = require('express-ws')(app);
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
res.sendFile(path.join(__dirname + '/static/index.html'));
|
||||
});
|
||||
|
||||
app.ws('/', function(ws, req) {
|
||||
const githubEvent = {}; // sample github Event from Github event API https://api.github.com/events
|
||||
ws.send('message', githubEvent);
|
||||
});
|
||||
|
||||
app.listen(port, function() {
|
||||
console.log('Listening on', port);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue