index.js
This file
Path
examples/view-constructor/index.js
47 lines · 1.1 KiB · JavaScript
Last changed by
Merge pull request #1592 from bartsqueezy/eb1bbb9TJ Holowaychukbefore adoptionc805d80
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
/** * Module dependencies. */
var express = require('../../') , http = require('http') , GithubView = require('./github-view') , md = require('marked').parse;
var app = module.exports = express();
// register .md as an engine in express view systemapp.engine('md', function(str, options, fn){ try { var html = md(str); html = html.replace(/\{([^}]+)\}/g, function(_, name){ return options[name] || ''; }) fn(null, html); } catch(err) { fn(err); }})
// pointing to a particular github repo to load files from itapp.set('views', 'visionmedia/express');
// register a new view constructorapp.set('view', GithubView);
app.get('/', function(req, res){ // rendering a view relative to the repo. // app.locals, res.locals, and locals passed // work like they normally would res.render('examples/markdown/views/index.md', { title: 'Example' });})
app.get('/Readme.md', function(req, res){ // rendering a view from https://github.com/visionmedia/express/blob/master/Readme.md res.render('Readme.md');})
if (!module.parent) { app.listen(3000); console.log('Express started on port 3000');}