connect-form
Version:
urlencoded / multipart form parsing middleware for Connect
215 lines (192 loc) • 6.72 kB
HTML
<html>
<head>
<title>Connect</title>
<meta http-equiv="content-type" value="text/html; charset=utf-8">
<style type="text/css">
body {
font: 13px "Helvetica Neue", "Lucida Grande", "Arial";
text-align: center;
color: #555;
-webkit-text-stroke: 1px rgba(255, 255, 255, 0.1);
}
h1, h2, h3 {
margin: 0;
font-size: 22px;
font-weight: normal;
color: #343434;
}
h2#Connect {
margin-bottom: 25px;
font-size: 60px;
font-weight: bold;
}
h2#Connect + p {
display: none;
}
h3 {
margin: 35px 0;
padding-left: 10px;
font-size: 16px;
border-left: 15px solid #eee;
}
h2 {
margin-top: 35px;
text-shadow: 1px 2px 2px #ddd;
}
ul {
margin: 10px 35px;
padding: 0;
}
ul li .path {
padding-left: 5px;
font-weight: bold;
}
ul li .line {
padding-right: 5px;
font-style: italic;
}
ul li:first-child .path {
padding-left: 0;
}
p {
line-height: 1.5;
}
p code {
padding: 2px 4px;
border: 1px solid #ddd;
}
p em, li em {
font-weight: bold;
}
pre {
margin: 25px 0 25px 15px;
padding: 15px;
border: 1px solid #ddd;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-webkit-box-shadow: 1px 1px 6px #ddd;
-moz-box-shadow: 1px 1px 6px #ddd;
}
table {
margin-bottom: 35px;
width: 100%;
border-collapse: collapse;
}
table td {
padding: 5px 10px;
font-size: 14px;
}
table tr {
border-bottom: 1px solid #fff;
}
table tr:last-child {
border-bottom: none;
}
table td:first-child {
width: 150px;
color: #343434;
}
#wrapper {
margin: 50px auto;
width: 750px;
text-align: left;
}
#menu {
position: fixed;
top: 15px;
right: 15px;
margin: 0;
padding: 0;
list-style: none;
text-align: right;
}
#menu li.title {
padding: 20px 0 5px 0;
font-size: 12px;
}
code.js { color: #111; }
code.js .comment { color: #999; }
code.js .string { color: #cc0000; }
code.js .number { color: #0000ee; }
code.js .keyword { color: #000; font-weight: bold; }
a {
text-decoration: none;
color: #000;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div id="wrapper">
<ul id="menu">
<li class="title">API</li>
<li><a href="api.html">extended api docs</a></li>
<li class="title">Middleware</li>
<li><a href="lint.html">lint</a></li>
<li><a href="flash.html">flash</a></li>
<li><a href="logger.html">logger</a></li>
<li><a href="format.html">format</a></li>
<li><a href="router.html">router</a></li>
<li><a href="jsonrpc.html">jsonrpc</a></li>
<li><a href="session.html">session</a></li>
<li><a href="compiler.html">compiler</a></li>
<li><a href="redirect.html">redirect</a></li>
<li><a href="errorHandler.html">errorHandler</a></li>
<li><a href="bodyDecoder.html">bodyDecoder</a></li>
<li><a href="responseTime.html">responseTime</a></li>
<li><a href="cookieDecoder.html">cookieDecoder</a></li>
<li><a href="conditionalGet.html">conditionalGet</a></li>
<li><a href="methodOverride.html">methodOverride</a></li>
<li><a href="staticProvider.html">staticProvider</a></li>
</ul><div class='mp'>
<h2 id="Session">Session</h2>
<p>The <em>session</em> middleware provides persistence between requests. If we wish to supply a custom <code>Store</code> subclass, or pass options to the store itself, we can configure it like so:</p>
<pre><code class="js"><span class="keyword">var</span> <span class="class">MemoryStore</span> = <span class="variable">require</span>(<span class="string">'connect/middleware/session/memory'</span>);
<span class="variable">connect</span>.<span class="variable">createServer</span>(
<span class="variable">connect</span>.<span class="variable">cookieDecoder</span>(),
<span class="variable">connect</span>.<span class="variable">session</span>({ <span class="variable">store</span>: <span class="keyword">new</span> <span class="class">MemoryStore</span>({ <span class="variable">reapInterval</span>: <span class="number integer">60000</span> * <span class="number integer">10</span> }) }),
);
</code></pre>
<p><strong>NOTE:</strong> <em>cookieDecoder</em> must be above <em>session</em> within the stack</p>
<h3 id="Options">Options</h3>
<pre><code>store Custom Store subclass
fingerprint Function passed the request which computes a fingerprint of the user.
Defaults to an md5 hash of the session.id, remoteAddress and User-Agent strings.
</code></pre>
<h3 id="Store">Store</h3>
<p>Abstract store which can be subclassed. To comply with <code>Store</code> you should define:</p>
<pre><code>#get(hash, callback) Fetch session data via the session fingerprint and callback(err, data)
#set(hash, data, callback) Commit the session for the fingerprint and callback(err)
</code></pre>
<p>Your store may also want to comply with the default MemoryStore, by providing:</p>
<pre><code>#clear(callback) Clear all sessions and callback(err)
#all(callback) Fetches all active sessions and callback(err, sessions)
#length(callback) Fetches the total number of sessions and callback(err, len)
</code></pre>
<p>Inherited methods defined by Store:</p>
<pre><code>#destroy(hash, callback) Calls #set(hash, null, callback)
#regenerate(req, callback) Destroys the session, creates a new one, and callback(err)
</code></pre>
<h3 id="MemoryStore">MemoryStore</h3>
<p>Stores session data in memory, options are as follows:</p>
<pre><code>reapInterval Interval in milliseconds used to reap stale sessions. Defaults to 10 minutes
maxAage Maximum session age in milliseconds. Defaults to 4 hours
cookie Session cookie options. Defaults to { path: '/', httpOnly: true }
</code></pre>
<h3 id="Session">Session</h3>
<p>Your store interacts with instances of <code>Session</code>. The following methods are available:</p>
<pre><code>#touch() Updates the lastAccess property
#destroy(callback) Destroy this session and callback(err, destroyedBoolean)
#regenerate(callback) Destroy this session, creates a new one and callback(err)
</code></pre>
<h3 id="See-Also">See Also</h3>
<ul>
<li>cookieDecoder</li>
</ul>
</div>
</div>
</body>
</html>