我正在尝试使用docpad来处理快速应用程序中的呈现,但在尝试访问/contact
时,请求似乎无限期地挂起。
这是我的申请:
var express = require('express');
var http = require('http');
var app = express();
var cons = require('consolidate');
var server = http.createServer(app).listen(process.env.PORT || 9778);
app.use(app.router);
// Add DocPad to our Application
var docpadInstanceConfiguration = {
// Give it our express application and http server
serverExpress: app,
serverHttp: server,
// Tell it not to load the standard middlewares (as we handled that above)
middlewareStandard: false
};
var docpadInstance = require('docpad').createInstance(docpadInstanceConfiguration, function(err){
if (err) return console.log(err.stack);
// Tell DocPad to perform a generation, extend our server with its routes, and watch for changes
docpadInstance.action('generate server watch', docpadInstanceConfiguration, function(err){
if (err) return console.log(err.stack);
});
});
app.get('/contact', function(req, res) {
req.templateData = {
weDidSomeCustomRendering: true
};
var d = docpadInstance.getFile({relativePath:'hello.html.md'});
docpadInstance.serveDocument({document: d, req: req, res: res}, function(){});
});
这几乎直接从文档中复制,但不起作用。有什么想法吗?
答案 0 :(得分:1)
关键是通过next
:
app.get('/contact', function(req, res, next) {
req.templateData = {
weDidSomeCustomRendering: true
};
var d = docpadInstance.getFileAtPath('pages/hello.html');
docpadInstance.serveDocument({document: d, req: req, res: res}, next);
});