Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
199 lines (190 sloc) 4.99 KB
<html>
<head>
<title>merlin</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style>body {
margin: 0;
padding: 0;
font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
color: #252519;
}
a {
color: #252519;
}
a:hover {
text-decoration: underline;
color: #19469D;
}
p {
margin: 12px 0;
}
h1, h2, h3 {
margin: 0;
padding: 0;
}
table#source {
width: 100%;
border-collapse: collapse;
}
table#source td:first-child {
padding: 30px 40px 30px 40px;
vertical-align: top;
}
table#source td:first-child,
table#source td:first-child pre {
width: 450px;
}
table#source td:last-child {
padding: 30px 0 30px 40px;
border-left: 1px solid #E5E5EE;
background: #F5F5FF;
}
table#source tr {
border-bottom: 1px solid #E5E5EE;
}
table#source tr.filename {
padding-top: 40px;
border-top: 1px solid #E5E5EE;
}
table#source tr.filename td:first-child {
text-transform: capitalize;
}
table#source tr.filename td:last-child {
font-size: 12px;
}
table#source tr.filename h2 {
margin: 0;
padding: 0;
cursor: pointer;
}
table#source tr.code h1,
table#source tr.code h2,
table#source tr.code h3 {
margin-top: 30px;
font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;
font-size: 18px;
}
table#source tr.code h2 {
font-size: 16px;
}
table#source tr.code h3 {
font-size: 14px;
}
table#source tr.code ul {
margin: 15px 0 15px 35px;
padding: 0;
}
table#source tr.code ul li {
margin: 0;
padding: 1px 0;
}
table#source tr.code ul li p {
margin: 0;
padding: 0;
}
table#source tr.code td:first-child pre {
padding: 20px;
}
#ribbon {
position: fixed;
top: 0;
right: 0;
}
code .string { color: #219161; }
code .regexp { color: #219161; }
code .keyword { color: #954121; }
code .number { color: #19469D; }
code .comment { color: #bbb; }
code .this { color: #19469D; }</style>
<script>
$(function(){
$('tr.code').hide();
$('tr.filename').toggle(function(){
$(this).nextUntil('.filename').fadeIn();
}, function(){
$(this).nextUntil('.filename').fadeOut();
});
});
</script>
</head>
<body>
<table id="source"><tbody><tr><td><h1>merlin</h1><p>object-oriented MVC framework for node.js</p></td><td></td></tr><tr class="filename"><td><h2 id="middleware/aliases.js"><a href="#">aliases</a></h2></td><td>middleware/aliases.js</td></tr><tr class="code">
<td class="docs">
<p>exports = module.exports = function aliases() {
return function aliases(req, res, next) {
with ({myself: module.exports}) {
myself.merlin().db().save('_design/aliases', {
all: {
map: function(doc) {
if (doc.type == 'pathAlias' &amp;&amp; doc.realPath &amp;&amp; doc.alias) {
emit(doc.id, doc);
}
}
},
byPath: {
map: function(doc) {
if (doc.type == 'pathAlias' &amp;&amp; doc.realPath &amp;&amp; doc.alias) {
emit(doc.path, doc);
}
}
},
byAlias: {
map: function(doc) {
if (doc.type == 'pathAlias' &amp;&amp; doc.realPath &amp;&amp; doc.alias) {
emit(doc.alias, doc);
}
}
}
});</p>
<pre><code> return function aliases(req, res, next) {
if (myself.aliasCache == null) {
myself.aliasCache = {};
db.view('aliases/all', function(err, result) {
result.forEach(function (docId, aliasRecord) {
myself.aliasCache[aliasRecord.alias] = aliasRecord.realPath;
});
});
}
var cleanedUrl = req.url.slice(1); // remove leading slash
if (cleanedUrl.indexOf('?') != -1) {
cleanedUrl = cleanedUrl.slice(0, cleanedUrl.indexOf('?'));
}
if (typeof myself.aliasCache[cleanedUrl] == 'string') {
console.log('Alias found, redirecting to', myself.aliasCache[cleanedUrl]);
console.log('(inside aliases middleware) redirecting');
res.redirect('/' + myself.aliasCache[cleanedUrl]);
} else {
console.log('(inside aliases middleware) nexting');
next();
}
}
}</code></pre>
<p> };
};</p>
<p>module.exports.aliasCache = null;</p>
</td>
<td class="code">
</td>
</tr><tr class="filename"><td><h2 id="middleware/sessionId.js"><a href="#">sessionId</a></h2></td><td>middleware/sessionId.js</td></tr><tr class="code">
<td class="docs">
<p>exports = module.exports = function sessionId(){
return function sessionId(req, res, next) {
if (req.session &amp;&amp; !req.session.sessionId) {
var hash = require('crypto').createHash('sha1');
hash.update(req.session.toString());
req.session.sessionId = hash.digest('base64');</p>
<pre><code> if (req.session.loggedIn == true) {
// set header -- Cache-Control: no-cache
// set header -- Expires: Fri, 31 Dec 1998 12:00:00 GMT (i.e., pick some date in past)
}
next();
} else {
next();
}</code></pre>
<p> }
};</p>
</td>
<td class="code">
</td>
</tr> </body>
</html></tbody></table>
Jump to Line
Something went wrong with that request. Please try again.