我正在尝试将我的简单节点js web应用程序放在AWS EB上,但似乎路径有问题。我正在我的机器上运行Windows并且它可以工作但是当我在EB上部署它时它会给我以下错误
Error: Failed to lookup view "pages/home" in views directory "/var/app/views"
at EventEmitter.render (/var/app/current/node_modules/express/lib/application.js:579:17)
at ServerResponse.render (/var/app/current/node_modules/express/lib/response.js:961:7)
at null.<anonymous> (/var/app/current/controller/app.js:113:14)
at tryCatcher (/var/app/current/node_modules/bluebird/js/release/util.js:16:23)
at Promise.successAdapter [as _fulfillmentHandler0] (/var/app/current/node_modules/bluebird/js/release/nodeify.js:23:30)
at Promise._settlePromise (/var/app/current/node_modules/bluebird/js/release/promise.js:557:21)
at Promise._settlePromise0 (/var/app/current/node_modules/bluebird/js/release/promise.js:605:10)
at Promise._settlePromises (/var/app/current/node_modules/bluebird/js/release/promise.js:684:18)
at Async._drainQueue (/var/app/current/node_modules/bluebird/js/release/async.js:126:16)
at Async._drainQueues (/var/app/current/node_modules/bluebird/js/release/async.js:136:10)
at Immediate.Async.drainQueues [as _onImmediate] (/var/app/current/node_modules/bluebird/js/release/async.js:16:14)
at processImmediate [as _immediateCallback] (timers.js:383:17)
我的路径代码
var path = require('path');
var app = express();
app.use(express.static(path.resolve('../public')));
app.set('views',path.resolve('../views'));
app.set('view engine', 'ejs');
答案 0 :(得分:0)
我假设您正在使用路径模块来解析目录和文件名(以避免Windows和Linux文件系统之间存在差异)。
它可能是文件权限或所有权问题。检查运行节点进程的用户是否具有对相关目录和文件的读取权限。
它也可能是路径解析问题。您的应用看起来像是 / var / app / current / ,但您尝试在 / var / app / views / 中查找文件。应该如果您的应用程序的结构是这样的,但如果您打算在 / var / app / current / views / 中查找文件,则会出现问题。
答案 1 :(得分:0)
仅关注区分大小写。确保在渲染器上传递的文件名与服务器上的文件完全相同...
例如 res.render(“挑战”,...正在查看文件名Challenge.hbs ...将会失败 res.render(“挑战”,...正在查看文件名Challenge.hbs ...将通过
答案 2 :(得分:0)
我有类似的问题,我的问题是我忘记了递归地将视图子目录压缩到我的根目录中,因此在部署到AWS Elastic Beanstalk时导致视图目录为空。因此,打包代码时,应使用zip -r example.zip .
之类的东西。