Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated dox

  • Loading branch information...
commit 126f96ddd96509a1b224c10c3f2bac306da8b0cf 1 parent 89c3e9b
@3rd-Eden authored
Showing with 33 additions and 15 deletions.
  1. +33 −15 index.html
View
48 index.html
@@ -120,15 +120,15 @@
</tr>
<tr class="code">
<td class="docs">
-<p>The server that does the Policy File servering</p>
+<p>The server that does the Policy File severing</p>
<h2>Options</h2>
-<ul><li><code>log</code> Should we output logging information to STDOUT and STDERR?</li></ul>
+<ul><li><code>log</code> false or a function that can output log information, defaults to console.log?</li></ul>
<h2></h2>
-<ul><li><p><strong>param</strong>: <em>Ojbect</em> options Options to customize the servers functionality.</p></li><li><p><strong>param</strong>: <em>Array</em> origins The origins that are allowed on this server, defaults to <code>*:*</code>.</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
+<ul><li><p><strong>param</strong>: <em>Object</em> options Options to customize the servers functionality.</p></li><li><p><strong>param</strong>: <em>Array</em> origins The origins that are allowed on this server, defaults to <code>*:*</code>.</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">function</span> <span class="class">Server</span>(<span class="variable">options</span>, <span class="variable">origins</span>){
@@ -136,7 +136,7 @@
<span class="this">this</span>.<span class="variable">origins</span> = <span class="variable">origins</span> || [<span class="string">'*:*'</span>];
<span class="this">this</span>.<span class="variable">port</span> = <span class="number integer">843</span>;
- <span class="this">this</span>.<span class="variable">log</span> = <span class="variable">true</span>;
+ <span class="this">this</span>.<span class="variable">log</span> = <span class="variable">console</span>.<span class="variable">log</span>;
<span class="comment">// merge `this` with the options</span>
<span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">options</span>).<span class="variable">forEach</span>(<span class="keyword">function</span>(<span class="variable">key</span>){
@@ -153,8 +153,8 @@
<span class="this">this</span>.<span class="variable">socket</span>.<span class="variable">on</span>(<span class="string">'error'</span>, <span class="keyword">function</span> <span class="variable">serverError</span>(<span class="variable">err</span>){
<span class="comment">// Special and common case error handling</span>
<span class="keyword">if</span> (<span class="variable">err</span>.<span class="variable">errno</span> == <span class="number integer">13</span>){
- <span class="variable">me</span>.<span class="variable">log</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">console</span>.<span class="variable">error</span>(
- <span class="keyword">new</span> <span class="class">Date</span>+ <span class="string">':@: Unable to listen to port `'</span> + <span class="variable">me</span>.<span class="variable">port</span> + <span class="string">'` as your Node.js instance does not have root privileges. '</span> +
+ <span class="variable">me</span>.<span class="variable">log</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">me</span>.<span class="variable">log</span>(
+ <span class="string">'Unable to listen to port `'</span> + <span class="variable">me</span>.<span class="variable">port</span> + <span class="string">'` as your Node.js instance does not have root privileges. '</span> +
(
<span class="variable">me</span>.<span class="variable">server</span>
? <span class="string">'The Flash Policy file will now be served inline over the supplied HTTP server, Flash Policy files request will suffer.'</span>
@@ -164,14 +164,16 @@
<span class="variable">me</span>.<span class="variable">socket</span>.<span class="variable">removeAllListeners</span>();
<span class="keyword">delete</span> <span class="variable">me</span>.<span class="variable">socket</span>;
+
+ <span class="variable">me</span>.<span class="variable">emit</span>(<span class="string">'connect_failed'</span>, <span class="variable">err</span>);
} <span class="keyword">else</span> {
- <span class="variable">me</span>.<span class="variable">log</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">console</span>.<span class="variable">error</span>(<span class="keyword">new</span> <span class="class">Date</span>+ <span class="string">':@: FlashPolicyFileServer received a error event:\n'</span> + (<span class="variable">err</span>.<span class="variable">message</span> ? <span class="variable">err</span>.<span class="variable">message</span> : <span class="variable">err</span>));
+ <span class="variable">me</span>.<span class="variable">log</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">me</span>.<span class="variable">log</span>(<span class="string">'FlashPolicyFileServer received a error event:\n'</span> + (<span class="variable">err</span>.<span class="variable">message</span> ? <span class="variable">err</span>.<span class="variable">message</span> : <span class="variable">err</span>));
}
});
<span class="this">this</span>.<span class="variable">socket</span>.<span class="variable">on</span>(<span class="string">'timeout'</span>, <span class="keyword">function</span> <span class="variable">serverTimeout</span>(){});
<span class="this">this</span>.<span class="variable">socket</span>.<span class="variable">on</span>(<span class="string">'close'</span>, <span class="keyword">function</span> <span class="variable">serverClosed</span>(<span class="variable">err</span>){
- <span class="variable">err</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">me</span>.<span class="variable">log</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">console</span>.<span class="variable">error</span>(<span class="keyword">new</span> <span class="class">Date</span>+ <span class="string">':@ Server closing due to an error: \n'</span> + (<span class="variable">err</span>.<span class="variable">message</span> ? <span class="variable">err</span>.<span class="variable">message</span> : <span class="variable">err</span>));
+ <span class="variable">err</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">me</span>.<span class="variable">log</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">me</span>.<span class="variable">log</span>(<span class="string">'Server closing due to an error: \n'</span> + (<span class="variable">err</span>.<span class="variable">message</span> ? <span class="variable">err</span>.<span class="variable">message</span> : <span class="variable">err</span>));
<span class="keyword">if</span> (<span class="variable">me</span>.<span class="variable">server</span>){
<span class="comment">// not online anymore</span>
@@ -183,10 +185,10 @@
<span class="variable">me</span>.<span class="variable">server</span>.<span class="variable">removeListener</span>(<span class="string">'connection'</span>, <span class="variable">me</span>.<span class="variable">server</span>[<span class="string">'@'</span>]);
}
}
- <span class="variable">me</span>.<span class="variable">log</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">console</span>.<span class="variable">log</span>(<span class="keyword">new</span> <span class="class">Date</span>+ <span class="string">':@: Shutting down FlashPolicyFileServer'</span>);
+ <span class="variable">me</span>.<span class="variable">log</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">me</span>.<span class="variable">log</span>(<span class="string">'Shutting down FlashPolicyFileServer'</span>);
});
- <span class="comment">// Compile the inital `buffer`</span>
+ <span class="comment">// Compile the initial `buffer`</span>
<span class="this">this</span>.<span class="variable">compile</span>();
}</code></pre>
</td>
@@ -223,6 +225,7 @@
<span class="comment">// if it's a Flash policy request, and we can write to the </span>
<span class="keyword">if</span> (
<span class="variable">data</span>
+ &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">data</span>[<span class="number integer">0</span>] === <span class="number integer">60</span>
&<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">data</span>.<span class="variable">toString</span>() === <span class="string">'&lt;policy-file-request/&gt;\0'</span>
&<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">socket</span>
&<span class="variable">amp</span>;&<span class="variable">amp</span>; (<span class="variable">socket</span>.<span class="variable">readyState</span> === <span class="string">'open'</span> || <span class="variable">socket</span>.<span class="variable">readyState</span> === <span class="string">'writeOnly'</span>)
@@ -237,7 +240,7 @@
}
<span class="comment">// We add a callback method, so we can set a flag for when the server is `enabled` or `online`.</span>
- <span class="comment">// this flag is needed because if a error occures and the we cannot boot up the server the</span>
+ <span class="comment">// this flag is needed because if a error occurs and the we cannot boot up the server the</span>
<span class="comment">// fallback functionality should not be removed during the `close` event</span>
<span class="this">this</span>.<span class="variable">socket</span>.<span class="variable">listen</span>(<span class="this">this</span>.<span class="variable">port</span>, <span class="keyword">function</span> <span class="variable">serverListening</span>(){
<span class="variable">me</span>.<span class="variable">socket</span>.<span class="variable">online</span> = <span class="variable">true</span>;
@@ -260,8 +263,22 @@
</td>
<td class="code">
<pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span> <span class="variable">add</span>(){
- <span class="keyword">var</span> <span class="variable">args</span> = <span class="variable">slice</span>.<span class="variable">call</span>(<span class="variable">arguments</span>, <span class="number integer">0</span>);
- <span class="class">Array</span>.<span class="variable">prototype</span>.<span class="variable">push</span>.<span class="variable">apply</span>(<span class="this">this</span>.<span class="variable">origins</span>, <span class="variable">args</span>);
+ <span class="keyword">var</span> <span class="variable">args</span> = <span class="variable">slice</span>.<span class="variable">call</span>(<span class="variable">arguments</span>, <span class="number integer">0</span>)
+ , <span class="variable">i</span> = <span class="variable">args</span>.<span class="variable">length</span>;
+
+ <span class="comment">// flag duplicates</span>
+ <span class="keyword">while</span> (<span class="variable">i</span>--){
+ <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">origins</span>.<span class="variable">indexOf</span>(<span class="variable">args</span>[<span class="variable">i</span>]) &<span class="variable">gt</span>;= <span class="number integer">0</span>){
+ <span class="variable">args</span>[<span class="variable">i</span>] = <span class="keyword">null</span>;
+ }
+ }
+
+ <span class="comment">// Add all the arguments to the array</span>
+ <span class="comment">// but first we want to remove all `falsy` values from the args</span>
+ <span class="class">Array</span>.<span class="variable">prototype</span>.<span class="variable">push</span>.<span class="variable">apply</span>(
+ <span class="this">this</span>.<span class="variable">origins</span>
+ , <span class="variable">args</span>.<span class="variable">filter</span>(<span class="keyword">function</span>(<span class="variable">value</span>){ <span class="keyword">return</span> !!<span class="variable">value</span> })
+ );
<span class="this">this</span>.<span class="variable">compile</span>();
<span class="keyword">return</span> <span class="this">this</span>;
@@ -307,7 +324,7 @@
</tr>
<tr class="code">
<td class="docs">
-<p>Proxy the eventlistener requests to the created Net server
+<p>Proxy the event listener requests to the created Net server
</p>
</td>
<td class="code">
@@ -351,7 +368,8 @@
</p>
</td>
<td class="code">
-<pre><code><span class="variable">exports</span>.<span class="variable">version</span> = <span class="string">'0.0.1'</span>;</code></pre>
+<pre><code><span class="variable">exports</span>.<span class="variable">version</span> = <span class="string">'0.0.2'</span>;
+</code></pre>
</td>
</tr> </body>
</html></tbody></table>
Please sign in to comment.
Something went wrong with that request. Please try again.