index.js
This file
Path
examples/view-constructor/index.js
48 lines · 1.1 KiB · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 2027b87 point at it.
fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87
lines 1–48why, one step back1'use strict'23/**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 it27app.set('views', 'expressjs/express');2829// 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){40 // rendering a view from https://github.com/expressjs/express/blob/master/Readme.md41 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}