integrating basic websocket
This commit is contained in:
28
dist/server/server.js
vendored
Executable file
28
dist/server/server.js
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express = require("express");
|
||||
const http = require("http");
|
||||
const WebSocket = require("ws");
|
||||
const app = express();
|
||||
//initialize a simple http server
|
||||
const server = http.createServer(app);
|
||||
//initialize the WebSocket server instance
|
||||
const wss = new WebSocket.Server({ server });
|
||||
wss.on('connection', (ws) => {
|
||||
//connection is up, let's add a simple simple event
|
||||
ws.on('message', (message) => {
|
||||
//log the received message and send it back to the client
|
||||
console.log('received: %s', message);
|
||||
ws.send(`Hello, you sent -> ${message}`);
|
||||
});
|
||||
//send immediatly a feedback to the incoming connection
|
||||
ws.send('Hi there, I am a WebSocket server');
|
||||
});
|
||||
// start our server
|
||||
server.listen(process.env.PORT || 80, () => {
|
||||
console.log(`Server started :)`);
|
||||
});
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Braid is running!\n');
|
||||
});
|
||||
//# sourceMappingURL=server.js.map
|
1
dist/server/server.js.map
vendored
Executable file
1
dist/server/server.js.map
vendored
Executable file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AACnC,6BAA6B;AAC7B,gCAAgC;AAEhC,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;AAEtB,iCAAiC;AACjC,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;AAEtC,0CAA0C;AAC1C,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAE7C,GAAG,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,EAAa,EAAE,EAAE;IAEnC,mDAAmD;IACnD,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAe,EAAE,EAAE;QAEjC,yDAAyD;QACzD,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QACrC,EAAE,CAAC,IAAI,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,uDAAuD;IACvD,EAAE,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC;AAEH,mBAAmB;AACnB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE;IACvC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACxB,GAAG,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC"}
|
Reference in New Issue
Block a user