-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
101 lines (92 loc) · 4.63 KB
/
index.ts
File metadata and controls
101 lines (92 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env node
import { WebSocket, WebSocketServer } from 'ws';
import * as path from 'path';
import * as express from 'express';
import { createServer } from 'http';
const chalk = require('chalk');
const PORT_WS = 4000;
const PORT_UI = '3000';
const wss = new WebSocketServer({ port: PORT_WS });
let clients = [];
const logo = `
***@ +**
** ******%
@** .......-:: ++%
#****% ................... *+
** . ..................... +
#*.... .............:--=- :. =
# . ...............:-%*%% %. =
** ..................*. *-+@. =
%*** .......... ** ...... ....... +
*# ....:::#********# .... .. .... =:
* .. ...:::****+=@@@@@@@@@@@ ....... #=
%* ..:. ...:: +*+.@@@@@@@@@@@@@@@@@@@@%###%%###*+
# ... ...:::++=@@@@@@@@%%%%%%%%@@@@@@@@@#%%-## ** =
*# . ..:::*++@@@@@@%%%%%%##%%%%%%%%@@@@@@@+###+:** ..
** ..:::=+-@@@@@%%% ##%%%%@@@@@@*.#@%+# ##..
%* ..:::*=%@@@@%%%%% ##%%%%%%@@@@+%%%%%*# #. *
*# ..:::.=@@@@@%%%%%%########* ####%%%%@@@@%*%## ## .
* .::::+.@@@@%%%%%%%%%%%#####* @*###%%%%@%@#%%#%-@% #.
* . :::::=@@%%%%%%%%%%#####%@= *####%%%%%%*### .%##%.
* .. .::::=@@%%%%%%#### *####%%%%%%%## %-# .
:* ..:::-@@%%%%####* @###*# *####%%%%%%#* ## -:
..*#* .:::-%@%%%%#### ######* *#####%%*##@ @# .:=*
=+ + =..:::%@%%%%#### ######* *#####%%#* .. ..:@+
%+ -= +..-: %%%%%####. ####%%%% =.. ... @#*
*+ = . + .--%%%%%%####* % ##%%%#-.... ... # *-
@*:++ : += -:%%%#######******#########%%%%%%%%%%%# =. #*:*
** ** : ++ =:%%%%##*********####%%%%%%%%%%%%%%@ :::...** :**
** ** . . .== . ### ++++++***####%%%%%%%%%%+ --:::: #* ::@#-
. ** ## === %** .::-++*###%% :.+-:::::::::@*% =---##%
. ** *#@ =--== :=**#%%%%% :..:....::.====-%**:.
+#@## *-: %*###%%%###- :::==++==@%#%..
+**:*## . .......:::::+===++==%%##.:.
. **#=#### ....:::--------==.-===+%%%#%::.
. . **#++#### .....:.::::::::-:::-====%%%*#%-:-:
... *##-+#####@ .. .::::::. .:::---%%%%#*#%---::
..:. **###*######%%@ .. ... @#%%%%%%#*#%.--=::
.... **##%=*####%%%%%%%%%%%#%****## ---:::
..... .*****%#%#=+***--####%=-:-:-:::
::::====---- ===--=::::
. .:.:::-:::--:::::::
.........:
`;
console.log(chalk.magenta(logo));
console.log(chalk.dim('─'.repeat(60)));
console.log(chalk.bold.white(' Amadeus | NgRx DevTools Server'));
console.log(chalk.dim('─'.repeat(60)));
wss.on('connection', (socket) => {
clients.push(socket);
socket.on('message', (message) => {
clients.forEach((client) => {
if (client !== socket && client.readyState === WebSocket.OPEN) {
client.send(message);
}
});
});
});
const app = express();
app.use(express.static(path.resolve(__dirname, 'ngrx-devtool-ui/browser')));
app.get('*', (_req, res) => {
res.sendFile(path.resolve(__dirname, 'ngrx-devtool-ui/browser/index.html'));
});
const uiServer = createServer(app);
uiServer.listen(Number(PORT_UI), () => {});
uiServer.on('error', (error) => {
console.error(chalk.red(` ✗ Failed to start UI server: ${error.message}`));
});
process.on('SIGINT', () => {
console.log(chalk.dim('\n\n Shutting down servers...'));
uiServer.close();
wss.close();
console.log(chalk.green(' ✓ Servers stopped. Goodbye!\n'));
process.exit(0);
});
console.log('');
console.log(chalk.green(` ✓ WebSocket`), chalk.dim(`ws://localhost:${PORT_WS}`));
console.log(chalk.green(` ✓ UI Server`), chalk.dim(`http://localhost:${PORT_UI}`));
console.log('');
console.log(chalk.dim('─'.repeat(60)));
console.log(chalk.dim(' Press'), chalk.white('Ctrl+C'), chalk.dim('to stop all servers'));
console.log(chalk.dim('─'.repeat(60)));
console.log('');