Skip to content

Commit 764c65e

Browse files
committed
docs updated
1 parent 695a34a commit 764c65e

File tree

2 files changed

+103
-22
lines changed

2 files changed

+103
-22
lines changed

docs/README.md.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,63 @@ <h2 id="server-class">Server Class</h2>
192192
</tr>
193193
</tbody>
194194
</table>
195+
<h2 id="request-uri-query-and-body">request uri, query, and, body</h2>
196+
<p>For handling api requests, posts, puts patches etc with body data, we are now making that available on the request as both a <code>String</code> and <code>Buffer</code> incase you need images or videos uploaded.</p>
197+
<table>
198+
<thead>
199+
<tr>
200+
<th>key</th>
201+
<th>type</th>
202+
<th>value</th>
203+
</tr>
204+
</thead>
205+
<tbody>
206+
<tr>
207+
<td>request.body</td>
208+
<td>string</td>
209+
<td>request body</td>
210+
</tr>
211+
<tr>
212+
<td>request.url</td>
213+
<td>string</td>
214+
<td>processed uri</td>
215+
</tr>
216+
<tr>
217+
<td>request.uri</td>
218+
<td>object</td>
219+
<td>parsed url information and query</td>
220+
</tr>
221+
<tr>
222+
<td>request.serverRoot</td>
223+
<td>string</td>
224+
<td>local dir for publicly served data</td>
225+
</tr>
226+
</tbody>
227+
</table>
228+
<table>
229+
<thead>
230+
<tr>
231+
<th>key</th>
232+
<th>type</th>
233+
<th>value</th>
234+
</tr>
235+
</thead>
236+
<tbody>
237+
<tr>
238+
<td>uri.protocol</td>
239+
<td>string</td>
240+
<td>protocol of request</td>
241+
</tr>
242+
<tr>
243+
<td>uri.host</td>
244+
<td>string</td>
245+
<td>hostname for domain</td>
246+
</tr>
247+
</tbody>
248+
</table>
249+
<p>uri.hostname |string| hostname for domain|
250+
|uri.query |object| parsed querystring|
251+
|uri.port |number| port request was received on|</p>
195252
<h3 id="-server-methods-http-riaevangelist-github-io-node-http-server-server-server-js-html-"><a href="http://riaevangelist.github.io/node-http-server/server/Server.js.html">Server Methods</a></h3>
196253
<h4 id="deploy">deploy</h4>
197254
<p><code>server.deploy</code> starts the server.</p>

docs/server/Server.js.html

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,31 @@ <h4 id="afterserve">afterServe</h4>
973973
}
974974

975975
request.url=uri;
976-
request.serverRoot=root;</pre></div>
976+
request.serverRoot=root;
977+
978+
request.body=<span class="hljs-string">''</span>;
979+
980+
request.on(
981+
<span class="hljs-string">'data'</span>,
982+
<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">chunk</span>)</span>{
983+
request.body+=chunk;
984+
}.bind(<span class="hljs-keyword">this</span>)
985+
).on(
986+
<span class="hljs-string">'end'</span>,
987+
<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
988+
<span class="hljs-keyword">if</span>(<span class="hljs-keyword">this</span>.config.verbose){
989+
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`###REQUEST BODY :
990+
<span class="hljs-subst">${request.body}</span>
991+
###
992+
`</span>);
993+
}
994+
995+
requestBodyComplete.bind(<span class="hljs-keyword">this</span>,request,response)();
996+
}.bind(<span class="hljs-keyword">this</span>)
997+
);
998+
}
999+
1000+
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">requestBodyComplete</span>(<span class="hljs-params">request,response</span>)</span>{</pre></div>
9771001
</div>
9781002
</li>
9791003

@@ -983,27 +1007,27 @@ <h4 id="afterserve">afterServe</h4>
9831007
<p>return any value to force or specify delayed or manual serving</p>
9841008

9851009
</div><div class="content">
986-
<div class="highlight"><pre> <span class="hljs-keyword">if</span>(
987-
<span class="hljs-keyword">this</span>.onRequest(
988-
request,
989-
response,
990-
completeServing.bind(<span class="hljs-keyword">this</span>)
991-
)
992-
){
993-
<span class="hljs-keyword">return</span>;
994-
};
995-
996-
<span class="hljs-keyword">const</span> filename = path.join(
997-
request.serverRoot,
998-
request.url
999-
);
1000-
1001-
fs.exists(
1002-
filename,
1003-
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fileExists</span>(<span class="hljs-params">exists</span>)</span>{
1004-
<span class="hljs-keyword">this</span>.serveFile(filename,exists,request,response);
1005-
}.bind(<span class="hljs-keyword">this</span>)
1006-
);
1010+
<div class="highlight"><pre> <span class="hljs-keyword">if</span>(
1011+
<span class="hljs-keyword">this</span>.onRequest(
1012+
request,
1013+
response,
1014+
completeServing.bind(<span class="hljs-keyword">this</span>)
1015+
)
1016+
){
1017+
<span class="hljs-keyword">return</span>;
1018+
};
1019+
1020+
<span class="hljs-keyword">const</span> filename = path.join(
1021+
request.serverRoot,
1022+
request.url
1023+
);
1024+
1025+
fs.exists(
1026+
filename,
1027+
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fileExists</span>(<span class="hljs-params">exists</span>)</span>{
1028+
<span class="hljs-keyword">this</span>.serveFile(filename,exists,request,response);
1029+
}.bind(<span class="hljs-keyword">this</span>)
1030+
);
10071031
}
10081032

10091033
<span class="hljs-built_in">module</span>.exports=<span class="hljs-keyword">new</span> Server;</pre></div>

0 commit comments

Comments
 (0)