我有以下 Node 代码:
var express = require('express');
var app = module.exports = express();
var phantom = require('node-phantom');
app.use('/', function (req, res) {
if (typeof(req.query._escaped_fragment_) !== "undefined") {
phantom.create(function (err, ph) {
return ph.createPage(function (err, page) {
return page.open("https://example.com/#!" + req.query._escaped_fragment_, function (status) {
return page.evaluate((function () {
return document.getElementsByTagName('html')[0].innerHTML;
}), function (err, result) {
res.send(result);
return ph.exit();
});
});
});
});
} else
res.render('index');
});
app.listen(3500);
console.log('Magic happens on port ' + 3500);
每当我尝试访问我的域时就会发生这种情况。但是,当我去那里时,我收到以下错误:
Error: No default engine was specified and no extension was provided.
谁能告诉我我做错了什么?
最佳答案
Express 正在尝试调用渲染,但您没有指定要使用哪个 View 引擎。这就是错误所在
如果您使用jade,请在调用应用程序后添加此配置
//change path to fit your use case of course
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
如果您只是尝试发送静态 html 文件,请使用 res.sendFile()
res.sendFile('/path/to/index.html')
关于javascript - 幻影 Node 未指定默认引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32740441/