@caboodle-tech/node-simple-server 2.0.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -10
- package/bin/nss.js +43 -9
- package/changelogs/v3.md +8 -0
- package/examples/controllers/prod-website.js +62 -0
- package/examples/controllers/websocket.js +1 -1
- package/examples/run.js +4 -0
- package/examples/www-production/assets/fonts/roboto/LICENSE.txt +202 -0
- package/examples/www-production/assets/fonts/roboto/roboto-regular.ttf +0 -0
- package/examples/www-production/assets/fonts/roboto/roboto-regular.woff +0 -0
- package/examples/www-production/assets/fonts/roboto/roboto-regular.woff2 +0 -0
- package/examples/www-production/assets/imgs/logo.png +0 -0
- package/examples/www-production/css/main.css +96 -0
- package/examples/www-production/css/normalize.css +349 -0
- package/examples/www-production/index.html +50 -0
- package/examples/www-production/js/main.js +33 -0
- package/handlers/live-reloading.html +34 -28
- package/handlers/websocket-only.html +153 -0
- package/package.json +5 -2
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
|
|
2
|
+
|
|
3
|
+
/* Document
|
|
4
|
+
========================================================================== */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 1. Correct the line height in all browsers.
|
|
8
|
+
* 2. Prevent adjustments of font size after orientation changes in iOS.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
html {
|
|
12
|
+
line-height: 1.15; /* 1 */
|
|
13
|
+
-webkit-text-size-adjust: 100%; /* 2 */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Sections
|
|
17
|
+
========================================================================== */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Remove the margin in all browsers.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
body {
|
|
24
|
+
margin: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Render the `main` element consistently in IE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
main {
|
|
32
|
+
display: block;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Correct the font size and margin on `h1` elements within `section` and
|
|
37
|
+
* `article` contexts in Chrome, Firefox, and Safari.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
h1 {
|
|
41
|
+
font-size: 2em;
|
|
42
|
+
margin: 0.67em 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Grouping content
|
|
46
|
+
========================================================================== */
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 1. Add the correct box sizing in Firefox.
|
|
50
|
+
* 2. Show the overflow in Edge and IE.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
hr {
|
|
54
|
+
box-sizing: content-box; /* 1 */
|
|
55
|
+
height: 0; /* 1 */
|
|
56
|
+
overflow: visible; /* 2 */
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 1. Correct the inheritance and scaling of font size in all browsers.
|
|
61
|
+
* 2. Correct the odd `em` font sizing in all browsers.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
pre {
|
|
65
|
+
font-family: monospace, monospace; /* 1 */
|
|
66
|
+
font-size: 1em; /* 2 */
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Text-level semantics
|
|
70
|
+
========================================================================== */
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Remove the gray background on active links in IE 10.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
a {
|
|
77
|
+
background-color: transparent;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 1. Remove the bottom border in Chrome 57-
|
|
82
|
+
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
abbr[title] {
|
|
86
|
+
border-bottom: none; /* 1 */
|
|
87
|
+
text-decoration: underline; /* 2 */
|
|
88
|
+
text-decoration: underline dotted; /* 2 */
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Add the correct font weight in Chrome, Edge, and Safari.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
b,
|
|
96
|
+
strong {
|
|
97
|
+
font-weight: bolder;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 1. Correct the inheritance and scaling of font size in all browsers.
|
|
102
|
+
* 2. Correct the odd `em` font sizing in all browsers.
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
code,
|
|
106
|
+
kbd,
|
|
107
|
+
samp {
|
|
108
|
+
font-family: monospace, monospace; /* 1 */
|
|
109
|
+
font-size: 1em; /* 2 */
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Add the correct font size in all browsers.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
small {
|
|
117
|
+
font-size: 80%;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Prevent `sub` and `sup` elements from affecting the line height in
|
|
122
|
+
* all browsers.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
sub,
|
|
126
|
+
sup {
|
|
127
|
+
font-size: 75%;
|
|
128
|
+
line-height: 0;
|
|
129
|
+
position: relative;
|
|
130
|
+
vertical-align: baseline;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
sub {
|
|
134
|
+
bottom: -0.25em;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
sup {
|
|
138
|
+
top: -0.5em;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* Embedded content
|
|
142
|
+
========================================================================== */
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Remove the border on images inside links in IE 10.
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
img {
|
|
149
|
+
border-style: none;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* Forms
|
|
153
|
+
========================================================================== */
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 1. Change the font styles in all browsers.
|
|
157
|
+
* 2. Remove the margin in Firefox and Safari.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
button,
|
|
161
|
+
input,
|
|
162
|
+
optgroup,
|
|
163
|
+
select,
|
|
164
|
+
textarea {
|
|
165
|
+
font-family: inherit; /* 1 */
|
|
166
|
+
font-size: 100%; /* 1 */
|
|
167
|
+
line-height: 1.15; /* 1 */
|
|
168
|
+
margin: 0; /* 2 */
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Show the overflow in IE.
|
|
173
|
+
* 1. Show the overflow in Edge.
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
button,
|
|
177
|
+
input { /* 1 */
|
|
178
|
+
overflow: visible;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Remove the inheritance of text transform in Edge, Firefox, and IE.
|
|
183
|
+
* 1. Remove the inheritance of text transform in Firefox.
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
button,
|
|
187
|
+
select { /* 1 */
|
|
188
|
+
text-transform: none;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Correct the inability to style clickable types in iOS and Safari.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
button,
|
|
196
|
+
[type="button"],
|
|
197
|
+
[type="reset"],
|
|
198
|
+
[type="submit"] {
|
|
199
|
+
-webkit-appearance: button;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Remove the inner border and padding in Firefox.
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
button::-moz-focus-inner,
|
|
207
|
+
[type="button"]::-moz-focus-inner,
|
|
208
|
+
[type="reset"]::-moz-focus-inner,
|
|
209
|
+
[type="submit"]::-moz-focus-inner {
|
|
210
|
+
border-style: none;
|
|
211
|
+
padding: 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Restore the focus styles unset by the previous rule.
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
button:-moz-focusring,
|
|
219
|
+
[type="button"]:-moz-focusring,
|
|
220
|
+
[type="reset"]:-moz-focusring,
|
|
221
|
+
[type="submit"]:-moz-focusring {
|
|
222
|
+
outline: 1px dotted ButtonText;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Correct the padding in Firefox.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
fieldset {
|
|
230
|
+
padding: 0.35em 0.75em 0.625em;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 1. Correct the text wrapping in Edge and IE.
|
|
235
|
+
* 2. Correct the color inheritance from `fieldset` elements in IE.
|
|
236
|
+
* 3. Remove the padding so developers are not caught out when they zero out
|
|
237
|
+
* `fieldset` elements in all browsers.
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
legend {
|
|
241
|
+
box-sizing: border-box; /* 1 */
|
|
242
|
+
color: inherit; /* 2 */
|
|
243
|
+
display: table; /* 1 */
|
|
244
|
+
max-width: 100%; /* 1 */
|
|
245
|
+
padding: 0; /* 3 */
|
|
246
|
+
white-space: normal; /* 1 */
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
progress {
|
|
254
|
+
vertical-align: baseline;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Remove the default vertical scrollbar in IE 10+.
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
textarea {
|
|
262
|
+
overflow: auto;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* 1. Add the correct box sizing in IE 10.
|
|
267
|
+
* 2. Remove the padding in IE 10.
|
|
268
|
+
*/
|
|
269
|
+
|
|
270
|
+
[type="checkbox"],
|
|
271
|
+
[type="radio"] {
|
|
272
|
+
box-sizing: border-box; /* 1 */
|
|
273
|
+
padding: 0; /* 2 */
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Correct the cursor style of increment and decrement buttons in Chrome.
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
[type="number"]::-webkit-inner-spin-button,
|
|
281
|
+
[type="number"]::-webkit-outer-spin-button {
|
|
282
|
+
height: auto;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 1. Correct the odd appearance in Chrome and Safari.
|
|
287
|
+
* 2. Correct the outline style in Safari.
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
[type="search"] {
|
|
291
|
+
-webkit-appearance: textfield; /* 1 */
|
|
292
|
+
outline-offset: -2px; /* 2 */
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Remove the inner padding in Chrome and Safari on macOS.
|
|
297
|
+
*/
|
|
298
|
+
|
|
299
|
+
[type="search"]::-webkit-search-decoration {
|
|
300
|
+
-webkit-appearance: none;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 1. Correct the inability to style clickable types in iOS and Safari.
|
|
305
|
+
* 2. Change font properties to `inherit` in Safari.
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
::-webkit-file-upload-button {
|
|
309
|
+
-webkit-appearance: button; /* 1 */
|
|
310
|
+
font: inherit; /* 2 */
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/* Interactive
|
|
314
|
+
========================================================================== */
|
|
315
|
+
|
|
316
|
+
/*
|
|
317
|
+
* Add the correct display in Edge, IE 10+, and Firefox.
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
details {
|
|
321
|
+
display: block;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/*
|
|
325
|
+
* Add the correct display in all browsers.
|
|
326
|
+
*/
|
|
327
|
+
|
|
328
|
+
summary {
|
|
329
|
+
display: list-item;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/* Misc
|
|
333
|
+
========================================================================== */
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Add the correct display in IE 10+.
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
template {
|
|
340
|
+
display: none;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Add the correct display in IE 10.
|
|
345
|
+
*/
|
|
346
|
+
|
|
347
|
+
[hidden] {
|
|
348
|
+
display: none;
|
|
349
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Website Demo</title>
|
|
7
|
+
<link rel="stylesheet" href="./css/normalize.css">
|
|
8
|
+
<link rel="stylesheet" href="./css/main.css">
|
|
9
|
+
<script src="./js/main.js" defer></script>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="page-container">
|
|
13
|
+
<header>
|
|
14
|
+
<div class="content">
|
|
15
|
+
<img class="logo" src="./assets/imgs/logo.png" title="Caboodle Tech Inc." alt="Caboodle Tech logo">
|
|
16
|
+
</div>
|
|
17
|
+
</header>
|
|
18
|
+
<main>
|
|
19
|
+
<div class="content">
|
|
20
|
+
<h1>Production Website/Application Demo</h1>
|
|
21
|
+
<p>
|
|
22
|
+
This is a simple demo of using Node Simple Server (NSS) for a static <i>production</i> website (HTML, CSS, JS). <strong>This is a good option for a web based internal work application.</strong> If NSS disconnects or crashes that will not be indicated to the user visually like in the website demo. You can still communicate with the backend via NSS websocket: <code>NSS_WS.send(...)</code>
|
|
23
|
+
</p>
|
|
24
|
+
<p>
|
|
25
|
+
You can also open the developer console to see helpful messages being printed by this demo.
|
|
26
|
+
</p>
|
|
27
|
+
<div id="fox-container">
|
|
28
|
+
<svg class="loader" version="1.1" id="L4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100" enable-background="new 0 0 0 0" xml:space="preserve">
|
|
29
|
+
<circle fill="#7d7d7d" stroke="none" cx="6" cy="50" r="6">
|
|
30
|
+
<animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.1"></animate>
|
|
31
|
+
</circle>
|
|
32
|
+
<circle fill="#7d7d7d" stroke="none" cx="26" cy="50" r="6">
|
|
33
|
+
<animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.2"></animate>
|
|
34
|
+
</circle>
|
|
35
|
+
<circle fill="#7d7d7d" stroke="none" cx="46" cy="50" r="6">
|
|
36
|
+
<animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.3"></animate>
|
|
37
|
+
</circle>
|
|
38
|
+
</svg>
|
|
39
|
+
</div>
|
|
40
|
+
<p id="fox-details"></p>
|
|
41
|
+
</div>
|
|
42
|
+
</main>
|
|
43
|
+
<footer>
|
|
44
|
+
<div class="content">
|
|
45
|
+
Made with <svg class="heart-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M18 1l-6 4-6-4-6 5v7l12 10 12-10v-7z"/></svg> by Caboodle Tech
|
|
46
|
+
</div>
|
|
47
|
+
</footer>
|
|
48
|
+
</div>
|
|
49
|
+
</body>
|
|
50
|
+
</html>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function loadFoxImage() {
|
|
2
|
+
|
|
3
|
+
const container = document.getElementById('fox-container');
|
|
4
|
+
if (!container) {
|
|
5
|
+
console.log('DEMO: Could not locate the image container for the fox image.');
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const details = document.getElementById('fox-details');
|
|
10
|
+
if (!details) {
|
|
11
|
+
console.log('DEMO: Could not locate the details container for the fox image.');
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
fetch('https://randomfox.ca/floof/')
|
|
16
|
+
.then((response) => response.json())
|
|
17
|
+
.then((json) => {
|
|
18
|
+
container.style.background = 'transparent';
|
|
19
|
+
container.innerHTML = `<img src="${json.image}">`;
|
|
20
|
+
details.innerHTML = `Image Source: <a href="${json.link}" target="_blank">${json.link}</a>`;
|
|
21
|
+
console.log('DEMO: Fox image successfully loaded.');
|
|
22
|
+
})
|
|
23
|
+
.catch((_) => {
|
|
24
|
+
console.log('DEMO: There was an error trying to load the fox image.');
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
29
|
+
console.log('DEMO: Loading a random image of a fox in 3 seconds...');
|
|
30
|
+
setTimeout(() => {
|
|
31
|
+
loadFoxImage();
|
|
32
|
+
}, 3000);
|
|
33
|
+
});
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
<style>
|
|
3
3
|
#NSS_WS{display:flex;justify-content:center;align-items:center;position:fixed;right:15px;bottom:15px;z-index:9000;width:80px;height:45px;border-radius:25px;background:#000}#NSS_WS svg{margin-left:5px;fill:#ffffff}#NSS_WS span{display:inline-block;margin-right:5px;font-family:monospace;font-size:22px;color:#fff}
|
|
4
4
|
</style>
|
|
5
|
-
<script type=
|
|
5
|
+
<script type='text/javascript'>
|
|
6
6
|
// <![CDATA[
|
|
7
|
-
if (
|
|
7
|
+
if ('WebSocket' in window) {
|
|
8
8
|
NSS_WS = (() => {
|
|
9
9
|
/** Handles showing the user the server disconnected and attempts to reconnect */
|
|
10
10
|
const disconnected = () => {
|
|
11
11
|
const icon = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd"><path d="M6.817 5.084l-2.057-2.937 1.639-1.147 14.601 20.853-1.638 1.147-1.401-2h-12.461c-3.037 0-5.5-2.463-5.5-5.5 0-2.702 1.951-4.945 4.521-5.408.105-1.965.965-3.73 2.296-5.008zm3.032-1.771c.681-.204 1.403-.313 2.151-.313 4.006 0 7.267 3.141 7.479 7.092 2.57.463 4.521 2.706 4.521 5.408 0 1.898-.962 3.571-2.424 4.56l-1.149-1.64c.947-.627 1.573-1.702 1.573-2.92 0-2.969-2.688-3.766-4.433-3.72.324-3.983-2.114-6.78-5.567-6.78-.317 0-.624.023-.922.068l-1.229-1.755zm-4.349 15.687h11.061l-8.595-12.274c-1.038 1.169-1.618 2.895-1.533 5.054-1.954-.113-4.433.923-4.433 3.72 0 1.93 1.57 3.5 3.5 3.5z"></path></svg>';
|
|
12
12
|
// Create the icon container.
|
|
13
|
-
let div = document.createElement(
|
|
14
|
-
div.id =
|
|
13
|
+
let div = document.createElement('DIV');
|
|
14
|
+
div.id = 'NSS_WS';
|
|
15
15
|
div.innerHTML = '<span id="NSS_WS_RETRY">02</span>' + icon;
|
|
16
16
|
// Add the container to the page.
|
|
17
17
|
if (document.body.firstChild) {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
// Keep updating the reconnect timer.
|
|
23
23
|
counterInterval = setInterval(function () {
|
|
24
|
-
var counter = document.getElementById(
|
|
24
|
+
var counter = document.getElementById('NSS_WS_RETRY');
|
|
25
25
|
var seconds = parseInt(counter.innerHTML) - 1;
|
|
26
26
|
if (seconds <= 0) {
|
|
27
27
|
seconds = 3000 * restartAttempts * 0.001;
|
|
@@ -40,17 +40,17 @@
|
|
|
40
40
|
|
|
41
41
|
/** Reload the pages stylesheets. */
|
|
42
42
|
const refreshCSS = () => {
|
|
43
|
-
const sheets = [].slice.call(document.getElementsByTagName(
|
|
44
|
-
const head = document.getElementsByTagName(
|
|
43
|
+
const sheets = [].slice.call(document.getElementsByTagName('link'));
|
|
44
|
+
const head = document.getElementsByTagName('head')[0];
|
|
45
45
|
for (let i = 0; i < sheets.length; i++) {
|
|
46
46
|
const elem = sheets[i];
|
|
47
47
|
const parent = elem.parentElement || head;
|
|
48
48
|
parent.removeChild(elem);
|
|
49
49
|
const rel = elem.rel;
|
|
50
|
-
if ((elem.href && typeof rel !=
|
|
51
|
-
const url = elem.href.replace(/(&|\?)_cacheOverride=\d+/,
|
|
52
|
-
let newUrl = url + (url.indexOf(
|
|
53
|
-
newUrl +=
|
|
50
|
+
if ((elem.href && typeof rel != 'string') || rel.length == 0 || rel.toLowerCase() == 'stylesheet') {
|
|
51
|
+
const url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
|
|
52
|
+
let newUrl = url + (url.indexOf('?') >= 0 ? '&' : '?');
|
|
53
|
+
newUrl += '_cacheOverride=' + new Date().valueOf();
|
|
54
54
|
elem.href = newUrl;
|
|
55
55
|
}
|
|
56
56
|
parent.appendChild(elem);
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
|
|
60
60
|
/** Register a function or functions to call when this page receives a WebSocket message. */
|
|
61
61
|
const registerCallback = (func) => {
|
|
62
|
-
if (whatIs(func) ===
|
|
62
|
+
if (whatIs(func) === 'function') {
|
|
63
63
|
callbacks.push(func);
|
|
64
64
|
}
|
|
65
65
|
};
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
http.open(
|
|
81
|
+
http.open('GET', window.location.href);
|
|
82
82
|
http.send();
|
|
83
83
|
// Keep attempting to reconnect unless told not to.
|
|
84
84
|
if (autoRestart) {
|
|
@@ -94,12 +94,12 @@
|
|
|
94
94
|
const send = (message) => {
|
|
95
95
|
if (ready && socket.readyState === WebSocket.OPEN) {
|
|
96
96
|
socket.send(JSON.stringify({
|
|
97
|
-
|
|
97
|
+
message,
|
|
98
98
|
type: whatIs(message)
|
|
99
99
|
}));
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
|
-
console.warn(
|
|
102
|
+
console.warn('Node Simple Server: The WebSocket is not ready or the connection was closed.');
|
|
103
103
|
};
|
|
104
104
|
|
|
105
105
|
/** Generate a random unique ID for this page; will be registered in the back-end. */
|
|
@@ -139,31 +139,37 @@
|
|
|
139
139
|
let restartAttempts = 0;
|
|
140
140
|
let restartInterval = null;
|
|
141
141
|
|
|
142
|
+
// Prep window path.
|
|
143
|
+
let pathname = window.location.pathname;
|
|
144
|
+
if (pathname === '/') {
|
|
145
|
+
pathname = '';
|
|
146
|
+
}
|
|
147
|
+
|
|
142
148
|
// Socket specific variables.
|
|
143
|
-
const protocol = window.location.protocol ===
|
|
144
|
-
const address = protocol
|
|
149
|
+
const protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
|
|
150
|
+
const address = `${protocol}{{HOST_ADDRESS}}${pathname}/ws?id=${pageId}`;
|
|
145
151
|
const socket = new WebSocket(address);
|
|
146
152
|
|
|
147
153
|
// Respond to messages the socket receives.
|
|
148
154
|
socket.onmessage = (evt) => {
|
|
149
155
|
const msgObj = JSON.parse(evt.data); // NSS uses a standard messaging object.
|
|
150
156
|
switch (msgObj.message) {
|
|
151
|
-
case
|
|
157
|
+
case 'close':
|
|
152
158
|
ready = false;
|
|
153
159
|
break;
|
|
154
|
-
case
|
|
160
|
+
case 'disableAutoRestart':
|
|
155
161
|
autoRestart = false;
|
|
156
162
|
clearInterval(restartInterval);
|
|
157
163
|
clearInterval(counterInterval);
|
|
158
|
-
console.log(
|
|
164
|
+
console.log('Node Simple Server: Auto restart disabled, manually refresh page if server disconnects.');
|
|
159
165
|
break;
|
|
160
166
|
case 'ping':
|
|
161
167
|
send('pong');
|
|
162
168
|
break;
|
|
163
|
-
case
|
|
169
|
+
case 'refreshCSS':
|
|
164
170
|
refreshCSS();
|
|
165
171
|
break;
|
|
166
|
-
case
|
|
172
|
+
case 'reload':
|
|
167
173
|
window.location.reload();
|
|
168
174
|
break;
|
|
169
175
|
default:
|
|
@@ -173,14 +179,14 @@
|
|
|
173
179
|
}
|
|
174
180
|
return;
|
|
175
181
|
}
|
|
176
|
-
console.log(`Received from WebSocket: ${msgObj.
|
|
182
|
+
console.log(`Received from WebSocket: ${msgObj.message}`);
|
|
177
183
|
}
|
|
178
184
|
};
|
|
179
185
|
|
|
180
186
|
// Mark the script as not ready when the websocket connection is closed.
|
|
181
|
-
socket.addEventListener(
|
|
187
|
+
socket.addEventListener('close', () => {
|
|
182
188
|
ready = false;
|
|
183
|
-
console.warn(
|
|
189
|
+
console.warn('Node Simple Server: Connection closed, live reload disabled.');
|
|
184
190
|
if (autoRestart) {
|
|
185
191
|
disconnected();
|
|
186
192
|
restartInterval = setInterval(restart, 3000);
|
|
@@ -188,8 +194,8 @@
|
|
|
188
194
|
});
|
|
189
195
|
|
|
190
196
|
// Mark the script as ready when a websocket connection is established.
|
|
191
|
-
socket.addEventListener(
|
|
192
|
-
console.log(
|
|
197
|
+
socket.addEventListener('open', () => {
|
|
198
|
+
console.log('Node Simple Server: Live reload enabled.');
|
|
193
199
|
ready = true;
|
|
194
200
|
});
|
|
195
201
|
|
|
@@ -203,7 +209,7 @@
|
|
|
203
209
|
};
|
|
204
210
|
})();
|
|
205
211
|
} else {
|
|
206
|
-
console.error(
|
|
212
|
+
console.error('Node Simple Server: This Browser does NOT support WebSocket for live reloading.');
|
|
207
213
|
}
|
|
208
214
|
// ]]>
|
|
209
215
|
</script>
|