Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用Docpad';express应用程序中的渲染引擎_Node.js_Express_Docpad - Fatal编程技术网

Node.js 使用Docpad';express应用程序中的渲染引擎

Node.js 使用Docpad';express应用程序中的渲染引擎,node.js,express,docpad,Node.js,Express,Docpad,我试图使用docpad在express应用程序中处理渲染,但当尝试访问/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 || 977

我试图使用docpad在express应用程序中处理渲染,但当尝试访问
/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(){});
});

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

关键是要通过
下一步

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

关键是通过
下一步

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