index.js
This file
Path
examples/view-constructor/index.js
47 lines · 1.2 KiB · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 6bc7574 point at it.
docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 1–47why, one step back1/**2 * Module dependencies.3 */45var express = require('../../');6var http = require('http');7var GithubView = require('./github-view');8var md = require('marked').parse;910var app = module.exports = express();1112// register .md as an engine in express view system13app.engine('md', function(str, options, fn){14 try {15 var html = md(str);16 html = html.replace(/\{([^}]+)\}/g, function(_, name){17 return options[name] || '';18 });19 fn(null, html);20 } catch(err) {21 fn(err);22 }23});2425// pointing to a particular github repo to load files from it26app.set('views', 'strongloop/express');2728// register a new view constructor29app.set('view', GithubView);3031app.get('/', function(req, res){32 // rendering a view relative to the repo.33 // app.locals, res.locals, and locals passed34 // work like they normally would35 res.render('examples/markdown/views/index.md', { title: 'Example' });36});3738app.get('/Readme.md', function(req, res){39 // rendering a view from https://github.com/strongloop/express/blob/master/Readme.md40 res.render('Readme.md');41});4243/* istanbul ignore next */44if (!module.parent) {45 app.listen(3000);46 console.log('Express started on port 3000');47}