28 lines
980 B
JavaScript
Executable File
28 lines
980 B
JavaScript
Executable File
"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
|