1

我正在尝试使用 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(){});
});

这几乎是直接从文档中复制的,但不起作用。有任何想法吗?

4

1 回答 1

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);
});

https://github.com/bevry/docpad/issues/706

于 2013-11-15T11:32:03.770 回答