Skip to content

Commit

Permalink
server lock using sessionStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
SomajitDey committed Sep 19, 2024
1 parent fb23079 commit 9a478cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ function config() {
}

function startWorker() {
if (myWorker) {
if (myWorker || sessionStorage.getItem("server")) {
alert('Another server is already running. Only one server can run at a time.');
return;
} else {
sessionStorage.setItem("server", "live");
}

myWorker = new Worker("app/bg-worker.js");

// Register handler for messages from the background worker
Expand Down Expand Up @@ -146,6 +150,7 @@ function stopWorker() {
}
myWorker.terminate();
myWorker = null;
sessionStorage.removeItem("server");
console.log("Worker terminated");
toggleServer.value = "Launch Server"
logThis("Server stopped");
Expand Down
8 changes: 5 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ <h3>About</h3>
</p>
<pre><code class="language-html">
&lt;!-- Replace XXXXX with the form action URL given by this app upon sign up` --&gt;
&lt;form action=&quot;XXXXX&quot; method=&quot;POST&quot; target=&quot;hidden_iframe&quot; autocomplete=&quot;on&quot;&gt;
&lt;form action=&quot;XXXXX&quot; method=&quot;POST&quot; target=&quot;hidden_iframe&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;From&quot; value=&quot;sample&quot;&gt;
&lt;input type=&quot;email&quot; name=&quot;Email&quot; placeholder=&quot;Your Email&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;Name&quot; placeholder=&quot;Your Name&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;Message&quot; placeholder=&quot;Your Message&quot; autocomplete=&quot;off&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;Message&quot; placeholder=&quot;Your Message&quot;&gt;
&lt;button type=&quot;submit&quot;&gt;Submit&lt;button&gt;
&lt;input type=&quot;reset&quot;&gt;Reset&lt;button&gt;
&lt;/form&gt;
Expand Down Expand Up @@ -102,7 +102,9 @@ <h3>Setup</h3>
<h3>Server</h3>
<div id="formActionURL"></div>
<div id="testForm">
<p>Test if everything is working properly with the following sample form. You should get a Telegram message upon clicking Post! Your posted data should also be logged below.</p>
<p>Test if everything is working properly with the following sample form (embed in your own website with
<button onclick="spaGoTo('about');">this code</button>). You should get a Telegram message upon clicking Post! Your posted data
should also be logged below.</p>
<form method="POST" target="hidden_iframe">
<input type="hidden" name="From" value="tester">
<div class="row mt-2">
Expand Down

0 comments on commit 9a478cd

Please sign in to comment.