Spaces:
Running
Running
Commit
·
82641f8
1
Parent(s):
0b10343
now animating the button when omnitool is ready
Browse files- myNodeServer.js +59 -22
myNodeServer.js
CHANGED
@@ -5,6 +5,7 @@ const PROXY_PORT = 4444; // Change this to a port different from 1688
|
|
5 |
const TARGET_HOST = '127.0.0.1';
|
6 |
const TARGET_PORT = 1688;
|
7 |
let OMNITOOL_READY = false;
|
|
|
8 |
let ALREADY_STARTING = false;
|
9 |
|
10 |
const VERSION = '0.0.4a';
|
@@ -28,9 +29,12 @@ async function startOmnitoolServer()
|
|
28 |
if (data.toString().includes(`Server has started and is ready to accept connections`))
|
29 |
{
|
30 |
console.log('Omnitool server started successfully');
|
31 |
-
|
|
|
|
|
32 |
OMNITOOL_READY = true;
|
33 |
-
resolve();
|
|
|
34 |
}
|
35 |
});
|
36 |
|
@@ -51,39 +55,40 @@ async function startOmnitoolServer()
|
|
51 |
});
|
52 |
}
|
53 |
|
54 |
-
async function startRequestForwardingServer()
|
|
|
55 |
const server = http.createServer((req, res) => handleRoutes(req, res));
|
56 |
server.listen(PROXY_PORT, '0.0.0.0');
|
57 |
console.log(`Request forwarding server listening on port ${PROXY_PORT}`);
|
58 |
-
|
59 |
|
60 |
async function handleRoutes(req, res)
|
61 |
{
|
62 |
-
if (
|
63 |
{
|
64 |
switch (req.url)
|
65 |
{
|
66 |
case '/start-omnitool-server':
|
67 |
{
|
68 |
|
69 |
-
console.log(`Omnitool Server:ALREADY_STARTING = ${ALREADY_STARTING}`)
|
70 |
if (ALREADY_STARTING)
|
71 |
{
|
72 |
-
res.writeHead(200, { 'Content-Type': 'text/html'});
|
73 |
res.end("Omnitool server already starting");
|
74 |
return;
|
75 |
}
|
76 |
try
|
77 |
{
|
78 |
await startOmnitoolServer();
|
79 |
-
res.writeHead(200, { 'Content-Type': 'text/html'});
|
80 |
res.end("Omnitool server started successfully");
|
81 |
}
|
82 |
catch (error)
|
83 |
{
|
84 |
console.error(error);
|
85 |
ALREADY_STARTING = false;
|
86 |
-
res.writeHead(500, { 'Content-Type': 'text/html'});
|
87 |
res.end(`Error starting Omnitool server: ${error}`);
|
88 |
}
|
89 |
|
@@ -92,16 +97,16 @@ async function handleRoutes(req, res)
|
|
92 |
|
93 |
case '/omnitool-logs':
|
94 |
{
|
95 |
-
res.writeHead(200, { 'Content-Type': 'application/json'});
|
96 |
-
const reply = { logs: omnitoolLogs, ready:
|
97 |
res.end(JSON.stringify(reply));
|
98 |
return;
|
99 |
}
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
<html>
|
106 |
<head>
|
107 |
<title>Proxy Server</title>
|
@@ -116,6 +121,18 @@ async function handleRoutes(req, res)
|
|
116 |
white-space: pre-wrap; /* Keep whitespaces */
|
117 |
border: 1px solid #ddd;
|
118 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
</style>
|
120 |
</head>
|
121 |
<body>
|
@@ -132,6 +149,11 @@ async function handleRoutes(req, res)
|
|
132 |
});
|
133 |
}
|
134 |
|
|
|
|
|
|
|
|
|
|
|
135 |
function startLogPolling() {
|
136 |
const interval = setInterval(() => {
|
137 |
fetch('/omnitool-logs')
|
@@ -142,7 +164,7 @@ async function handleRoutes(req, res)
|
|
142 |
if (data.ready) {
|
143 |
logContainer.innerText = "Omnitool is ready! Please open the following link in a new tab: https://${localUrl}";
|
144 |
clearInterval(interval);
|
145 |
-
|
146 |
}
|
147 |
scrollToBottom(logContainer);
|
148 |
});
|
@@ -157,17 +179,32 @@ async function handleRoutes(req, res)
|
|
157 |
</script>
|
158 |
</body>
|
159 |
</html>`;
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
|
166 |
default:
|
167 |
console.log(`Doing nothing with this request: ${req.url}`);
|
168 |
res.writeHead(200, { 'Content-Type': 'text/html' });
|
169 |
-
res.end(`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
return;
|
|
|
171 |
}
|
172 |
}
|
173 |
const options = { hostname: TARGET_HOST, port: TARGET_PORT, path: req.url, method: req.method, headers: req.headers, };
|
|
|
5 |
const TARGET_HOST = '127.0.0.1';
|
6 |
const TARGET_PORT = 1688;
|
7 |
let OMNITOOL_READY = false;
|
8 |
+
let OMNITOOL_PRE_READY = false;
|
9 |
let ALREADY_STARTING = false;
|
10 |
|
11 |
const VERSION = '0.0.4a';
|
|
|
29 |
if (data.toString().includes(`Server has started and is ready to accept connections`))
|
30 |
{
|
31 |
console.log('Omnitool server started successfully');
|
32 |
+
OMNITOOL_PRE_READY = true;
|
33 |
+
setTimeout(() =>
|
34 |
+
{
|
35 |
OMNITOOL_READY = true;
|
36 |
+
resolve();
|
37 |
+
}, 1000); // Delay by 1 second
|
38 |
}
|
39 |
});
|
40 |
|
|
|
55 |
});
|
56 |
}
|
57 |
|
58 |
+
async function startRequestForwardingServer()
|
59 |
+
{
|
60 |
const server = http.createServer((req, res) => handleRoutes(req, res));
|
61 |
server.listen(PROXY_PORT, '0.0.0.0');
|
62 |
console.log(`Request forwarding server listening on port ${PROXY_PORT}`);
|
63 |
+
}
|
64 |
|
65 |
async function handleRoutes(req, res)
|
66 |
{
|
67 |
+
if (!OMNITOOL_READY && (req.method === 'GET'))
|
68 |
{
|
69 |
switch (req.url)
|
70 |
{
|
71 |
case '/start-omnitool-server':
|
72 |
{
|
73 |
|
74 |
+
console.log(`Omnitool Server:ALREADY_STARTING = ${ALREADY_STARTING}`);
|
75 |
if (ALREADY_STARTING)
|
76 |
{
|
77 |
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
78 |
res.end("Omnitool server already starting");
|
79 |
return;
|
80 |
}
|
81 |
try
|
82 |
{
|
83 |
await startOmnitoolServer();
|
84 |
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
85 |
res.end("Omnitool server started successfully");
|
86 |
}
|
87 |
catch (error)
|
88 |
{
|
89 |
console.error(error);
|
90 |
ALREADY_STARTING = false;
|
91 |
+
res.writeHead(500, { 'Content-Type': 'text/html' });
|
92 |
res.end(`Error starting Omnitool server: ${error}`);
|
93 |
}
|
94 |
|
|
|
97 |
|
98 |
case '/omnitool-logs':
|
99 |
{
|
100 |
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
101 |
+
const reply = { logs: omnitoolLogs, ready: OMNITOOL_PRE_READY };
|
102 |
res.end(JSON.stringify(reply));
|
103 |
return;
|
104 |
}
|
105 |
|
106 |
+
case '/':
|
107 |
+
{
|
108 |
+
const localUrl = req.headers['host'];
|
109 |
+
let htmlContent = `
|
110 |
<html>
|
111 |
<head>
|
112 |
<title>Proxy Server</title>
|
|
|
121 |
white-space: pre-wrap; /* Keep whitespaces */
|
122 |
border: 1px solid #ddd;
|
123 |
}
|
124 |
+
.highlight-button {
|
125 |
+
animation: pulseAnimation 1s infinite;
|
126 |
+
background-color: yellow;
|
127 |
+
color: black;
|
128 |
+
font-weight: bold;
|
129 |
+
}
|
130 |
+
@keyframes pulseAnimation {
|
131 |
+
0% { transform: scale(1); }
|
132 |
+
50% { transform: scale(1.1); }
|
133 |
+
100% { transform: scale(1); }
|
134 |
+
}
|
135 |
+
</style>
|
136 |
</style>
|
137 |
</head>
|
138 |
<body>
|
|
|
149 |
});
|
150 |
}
|
151 |
|
152 |
+
function highlightExitButton() {
|
153 |
+
const exitButton = document.getElementById('exitIframeButton');
|
154 |
+
exitButton.classList.add('highlight-button');
|
155 |
+
}
|
156 |
+
|
157 |
function startLogPolling() {
|
158 |
const interval = setInterval(() => {
|
159 |
fetch('/omnitool-logs')
|
|
|
164 |
if (data.ready) {
|
165 |
logContainer.innerText = "Omnitool is ready! Please open the following link in a new tab: https://${localUrl}";
|
166 |
clearInterval(interval);
|
167 |
+
highlightExitButton();
|
168 |
}
|
169 |
scrollToBottom(logContainer);
|
170 |
});
|
|
|
179 |
</script>
|
180 |
</body>
|
181 |
</html>`;
|
182 |
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
183 |
+
res.end(htmlContent);
|
184 |
+
return;
|
185 |
+
}
|
186 |
+
|
187 |
|
188 |
default:
|
189 |
console.log(`Doing nothing with this request: ${req.url}`);
|
190 |
res.writeHead(200, { 'Content-Type': 'text/html' });
|
191 |
+
res.end(`
|
192 |
+
<html>
|
193 |
+
<head>
|
194 |
+
<title>Page Refresh</title>
|
195 |
+
<script>
|
196 |
+
setTimeout(function() {
|
197 |
+
window.location.reload(1);
|
198 |
+
}, 5000); // Refreshes after 5 seconds
|
199 |
+
</script>
|
200 |
+
</head>
|
201 |
+
<body>
|
202 |
+
<p>Doing nothing with this request: ${req.url}</p>
|
203 |
+
<p>The page will refresh automatically in 5 seconds.</p>
|
204 |
+
</body>
|
205 |
+
</html>`);
|
206 |
return;
|
207 |
+
|
208 |
}
|
209 |
}
|
210 |
const options = { hostname: TARGET_HOST, port: TARGET_PORT, path: req.url, method: req.method, headers: req.headers, };
|