2018-11-04 22:46:50 +00:00
|
|
|
/* 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;
|
|
|
|
|
2019-01-14 09:09:09 +00:00
|
|
|
const app = uWS./*SSL*/App({
|
2018-12-26 12:50:12 +00:00
|
|
|
key_file_name: '/home/alexhultman/key.pem',
|
|
|
|
cert_file_name: '/home/alexhultman/cert.pem',
|
|
|
|
passphrase: '1234'
|
2019-01-14 11:44:29 +00:00
|
|
|
}).get('/static/:param', (res, req) => {
|
|
|
|
res.end('Hello, your url is ' + req.getUrl() + ". The param1 is " + req.getParameter(0));
|
2018-12-26 12:50:12 +00:00
|
|
|
}).get('/hello', (res, req) => {
|
2019-01-14 11:44:29 +00:00
|
|
|
res.end('Hej, du är på url: ' + req.getUrl());
|
2018-12-26 12:50:12 +00:00
|
|
|
}).ws('/*', {
|
2019-01-14 09:09:09 +00:00
|
|
|
compression: 0,
|
2019-01-08 21:04:56 +00:00
|
|
|
maxPayloadLength: 16 * 1024 * 1024,
|
2018-12-26 12:50:12 +00:00
|
|
|
open: (ws, req) => {
|
2018-12-26 14:23:14 +00:00
|
|
|
console.log(ws);
|
2018-12-26 12:50:12 +00:00
|
|
|
},
|
2019-01-08 21:04:56 +00:00
|
|
|
message: (ws, message, isBinary) => {
|
|
|
|
ws.send(message, isBinary);
|
2019-01-14 11:16:24 +00:00
|
|
|
|
|
|
|
console.log('BufferedAmount is ' + ws.getBufferedAmount());
|
|
|
|
|
|
|
|
ws.close();
|
2019-01-14 09:09:09 +00:00
|
|
|
},
|
|
|
|
drain: (ws) => {
|
|
|
|
console.log('WebSocket drained');
|
|
|
|
},
|
|
|
|
close: (ws, code, message) => {
|
|
|
|
console.log('WebSocket closed');
|
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);
|
|
|
|
}
|
|
|
|
});
|