Browse Source

Update Node.js pinging examples -- handle the 'error' event.

pull/409/head
Pēteris Caune 4 years ago
parent
commit
5acea4c89d
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
4 changed files with 12 additions and 4 deletions
  1. +3
    -1
      templates/docs/javascript.html
  2. +3
    -1
      templates/docs/javascript.md
  3. +3
    -1
      templates/front/snippets/node.html
  4. +3
    -1
      templates/front/snippets/node.txt

+ 3
- 1
templates/docs/javascript.html View File

@ -1,7 +1,9 @@
<h1>Javascript</h1> <h1>Javascript</h1>
<p>Below is an example of making a HTTP request to SITE_NAME from Node.js.</p> <p>Below is an example of making a HTTP request to SITE_NAME from Node.js.</p>
<div class="js highlight"><pre><span></span><code><span class="kd">var</span> <span class="nx">https</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;https&#39;</span><span class="p">);</span> <div class="js highlight"><pre><span></span><code><span class="kd">var</span> <span class="nx">https</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;https&#39;</span><span class="p">);</span>
<span class="nx">https</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s2">&quot;PING_URL&quot;</span><span class="p">);</span>
<span class="nx">https</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;PING_URL&#39;</span><span class="p">).</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Ping failed: &#39;</span> <span class="o">+</span> <span class="nx">err</span><span class="p">)</span>
<span class="p">});</span>
</code></pre></div> </code></pre></div>


+ 3
- 1
templates/docs/javascript.md View File

@ -4,7 +4,9 @@ Below is an example of making a HTTP request to SITE_NAME from Node.js.
```js ```js
var https = require('https'); var https = require('https');
https.get("PING_URL");
https.get('PING_URL').on('error', (err) => {
console.log('Ping failed: ' + err)
});
``` ```
You can also send pings from a browser environment. SITE_NAME sets the You can also send pings from a browser environment. SITE_NAME sets the


+ 3
- 1
templates/front/snippets/node.html View File

@ -1,3 +1,5 @@
<div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">https</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;https&#39;</span><span class="p">);</span> <div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">https</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;https&#39;</span><span class="p">);</span>
<span class="nx">https</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s2">&quot;{{ ping_url }}&quot;</span><span class="p">);</span>
<span class="nx">https</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;{{ ping_url }}&#39;</span><span class="p">).</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Ping failed: &#39;</span> <span class="o">+</span> <span class="nx">err</span><span class="p">)</span>
<span class="p">});</span>
</pre></div> </pre></div>

+ 3
- 1
templates/front/snippets/node.txt View File

@ -1,2 +1,4 @@
var https = require('https'); var https = require('https');
https.get("PING_URL");
https.get('PING_URL').on('error', (err) => {
console.log('Ping failed: ' + err)
});

Loading…
Cancel
Save