index.js
This file
Path
examples/view-constructor/index.js
48 lines · 1.1 KiB · JavaScript
Last changed by
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
History of this fileTake it
The walk stopped after 200 commits: lines older than 2a0c35a point at it.
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
lines 1–2why, one step back1'use strict'2Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 3–26why, one step back3/**4 * Module dependencies.5 */67var express = require('../../');8var GithubView = require('./github-view');9var md = require('marked').parse;1011var app = module.exports = express();1213// register .md as an engine in express view system14app.engine('md', function(str, options, fn){15 try {16 var html = md(str);17 html = html.replace(/\{([^}]+)\}/g, function(_, name){18 return options[name] || '';19 });20 fn(null, html);21 } catch(err) {22 fn(err);23 }24});2526// pointing to a particular github repo to load files from itMerge tag '4.13.4'Douglas Christopher Wilsonbefore adoption7cafdb5
line 27why, one step back27app.set('views', 'expressjs/express');Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 28–39why, one step back2829// register a new view constructor30app.set('view', GithubView);3132app.get('/', function(req, res){33 // rendering a view relative to the repo.34 // app.locals, res.locals, and locals passed35 // work like they normally would36 res.render('examples/markdown/views/index.md', { title: 'Example' });37});3839app.get('/Readme.md', function(req, res){Merge tag '4.13.4'Douglas Christopher Wilsonbefore adoption7cafdb5
line 40why, one step back40 // rendering a view from https://github.com/expressjs/express/blob/master/Readme.mdInvoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 41–48why, one step back41 res.render('Readme.md');42});4344/* istanbul ignore next */45if (!module.parent) {46 app.listen(3000);47 console.log('Express started on port 3000');48}