Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ Thumbs.db

# Logs
npm-debug.log

# dotenv environment variables file
.env
.env.test

# build / generate output
/dist
9 changes: 0 additions & 9 deletions index.js

This file was deleted.

27 changes: 27 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { httpServer } from './src/http_server/index';
import { createWebSocketStream, WebSocketServer } from 'ws';
import { handle } from './src/actions/actions_controller';
import { Duplex } from 'stream';

const HTTP_PORT = 3000;
httpServer.listen(HTTP_PORT)
console.log(`Static http server started on http://localhost:${HTTP_PORT}`);

const WS_PORT = 8080;
const server = new WebSocketServer({ port: WS_PORT });

server.on('connection', (socket) => {
const duplex: Duplex = createWebSocketStream(socket, { decodeStrings: false });
duplex.write(`connection_established\0`);
duplex.write(`port_${WS_PORT}\0`);
duplex.on('error', console.error);

duplex.on('data', async (chunk) => {
const command: string[] = chunk.toString().split(' ');
duplex.write(await handle(command));
})

socket.on('close', () => {
console.log('closed the connection');
})
});
Loading