uWebSockets.js/examples/HelloWorld.js

28 lines
779 B
JavaScript
Raw Normal View History

/* The stand-alone runtime has uWS namespace already loaded. */
var uWS = uWS ? uWS : require('../dist/uws.js');
2018-10-28 15:07:21 +00:00
2018-12-26 18:19:26 +00:00
const port = 9001;
// nice milestone to pass autobahn on both ssl and non-ssl with an without compression
2018-10-28 15:07:21 +00:00
2018-12-26 12:50:12 +00:00
const app = uWS./*SSL*/App({
key_file_name: '/home/alexhultman/key.pem',
cert_file_name: '/home/alexhultman/cert.pem',
passphrase: '1234'
}).get('/hello', (res, req) => {
res.end('Hejdå!');
}).ws('/*', {
open: (ws, req) => {
2018-12-26 14:23:14 +00:00
console.log(ws);
2018-12-26 12:50:12 +00:00
},
2018-12-26 18:19:26 +00:00
message: (ws, message, opCode) => {
ws.send(message, opCode); // need op to pass autobahn (guess binary on off is enough?)
2018-12-26 12:50:12 +00:00
}
2018-10-28 15:07:21 +00:00
}).listen(port, (token) => {
if (token) {
console.log('Listening to port ' + port);
} else {
console.log('Failed to listen to port ' + port);
}
});