我正在使用sails.js,但我正在尝试更改并使用pomelo.js。
两者都基于 express.js。
但是我遇到了一些麻烦,这里是我的 web-server/app.js
var express = require('express'); var app = express(); 变量端口 = 1337; // 假设帮助并使用 EJS 渲染器读取 .html 文件 app.engine('.html', require('ejs').__express);
app.configure(function(){ app.use(express.methodOverride());
app.use(express.bodyParser()); app.use(app.router); app.set('view engine', 'ejs '); app.set('views', _ dirname + '/public/views');
app.set('view options', {layout: 'layout'}); // 布局的名称?没有找到关于查看选项... app.set('basepath', _dirname + '/public'); });app.configure('development', function(){
app.use(express.static(__dirname + '/public/views/main')); app.use(express.errorHandler({ dumpExceptions: true, showStack: true } )); });app.configure('production', function(){ var oneYear = 31557600000;
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.errorHandler()) ; });console.log("Web服务器已经启动。\n请登录 http://localhost.com :"+port+"/index.html");
app.listen(端口);
但是当我进入页面时,EJS 代码不会被解释而是显示。我在views/main 中的文件叫做index.html。我试图将其称为 index.ejs,但如果我这样做,我会收到消息:无法获取 /
所以我不知道该怎么做,我尝试了很多东西,我阅读了 express.js 文档并搜索示例,但没有任何效果。我在用着
"lodash": "~2.2.1",
"ejs": "~0.8.4",
"express": "~3.4.0"
谢谢您的帮助。PS:请加标签pomelo.js,我不能。 http://pomelo.netease.com/