https, max send size

This commit is contained in:
Josh Burman
2019-02-28 23:21:06 -05:00
parent b8282bf009
commit 97ed2476f4
523 changed files with 108 additions and 812666 deletions

View File

@ -1,34 +1,49 @@
import * as express from 'express';
import * as http from 'http';
import * as https from 'https';
import * as WebSocket from 'ws';
import * as fs from 'fs';
var privateKey = fs.readFileSync('certs/key.pem', 'utf8');
var certificate = fs.readFileSync('certs/cert.pem', 'utf8');
var credentials = {key: privateKey, cert: certificate};
const app = express();
//initialize a simple http server
const server = http.createServer(app);
//initialize the WebSocket server instance
const wss = new WebSocket.Server({ server });
const server = https.createServer(credentials, app);
const wss = new WebSocket.Server({ server, maxPayload:250000 });
wss.on('connection', (ws: WebSocket) => {
console.log('client connected')
//connection is up, let's add a simple simple event
ws.on('message', (message: string) => {
//log the received message and send it back to the client
console.log('received: %s', message);
ws.send(`Hello, you sent -> ${message}`);
const broadcastRegex = /^broadcast\:/;
if (broadcastRegex.test(message)) {
message = message.replace(broadcastRegex, '');
//send back the message to the other clients
wss.clients
.forEach(client => {
if (client != ws) {
client.send(`Hello, broadcast message -> ${message}`);
}
});
} else {
ws.send(`Hello, you sent -> ${message}`);
}
});
//send immediatly a feedback to the incoming connection
ws.send('Hi there, I am a WebSocket server');
ws.send('Hi there, welcome to braid, Measures Web Socket server.\nConnecting all our services!');
});
// start our server
server.listen(process.env.PORT || 80, () => {
server.listen(process.env.PORT || 8443, () => {
console.log(`Server started :)`);
});
app.get('/', (req, res) => {
res.send('Braid is running!\n');
res.send('Braid v0.1.2 is running!\n');
});