work.suroh.tk/node_modules/nunjucks/samples/express/main.js

38 lines
696 B
JavaScript
Raw Normal View History

2019-12-02 12:22:45 +00:00
/* eslint-disable func-names */
'use strict';
var path = require('path');
var nunjucks = require('../..');
var express = require('express');
var app = express();
nunjucks.configure(path.join(__dirname, 'views'), {
autoescape: true,
express: app,
watch: true
});
// app
app.use(express.static(__dirname));
app.use(function(req, res, next) {
res.locals.user = 'hello';
next();
});
app.get('/', function(req, res) {
res.render('index.html', {
username: 'James Long <strong>copyright</strong>'
});
});
app.get('/about', function(req, res) {
res.render('about.html');
});
app.listen(4000, function() {
console.log('Express server running on http://localhost:4000');
});