fix: added a missing semicolon in css styles in examples/auth (#6297)
[express.git] / examples / view-constructor / index.js
blob3d673670e312ef24de903e30e3cff86b95cdd4da
1 'use strict'
3 /**
4 * Module dependencies.
5 */
7 var express = require('../../');
8 var GithubView = require('./github-view');
9 var md = require('marked').parse;
11 var app = module.exports = express();
13 // register .md as an engine in express view system
14 app.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);
24 });
26 // pointing to a particular github repo to load files from it
27 app.set('views', 'expressjs/express');
29 // register a new view constructor
30 app.set('view', GithubView);
32 app.get('/', function(req, res){
33 // rendering a view relative to the repo.
34 // app.locals, res.locals, and locals passed
35 // work like they normally would
36 res.render('examples/markdown/views/index.md', { title: 'Example' });
37 });
39 app.get('/Readme.md', function(req, res){
40 // rendering a view from https://github.com/expressjs/express/blob/master/Readme.md
41 res.render('Readme.md');
42 });
44 /* istanbul ignore next */
45 if (!module.parent) {
46 app.listen(3000);
47 console.log('Express started on port 3000');