在本地运行此Express 应用程序有效。在Heroku上运行它会在请求/
或请求时给出粘贴错误/nested
Error: Failed to lookup view "index"
at Function.app.render (/app/node_modules/express/lib/application.js:493:17)
at ServerResponse.res.render (/app/node_modules/express/lib/response.js:753:7)
at /app/server.js:21:16
at callbacks (/app/node_modules/express/lib/router/index.js:161:37)
at param (/app/node_modules/express/lib/router/index.js:135:11)
at pass (/app/node_modules/express/lib/router/index.js:142:5)
at Router._dispatch (/app/node_modules/express/lib/router/index.js:170:5)
at Object.router (/app/node_modules/express/lib/router/index.js:33:10)
at next (/app/node_modules/express/node_modules/connect/lib/proto.js:199:15)
at store.get.next (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:309:9)
Error: Failed to lookup view "nested/index"
at Function.app.render (/app/node_modules/express/lib/application.js:493:17)
at ServerResponse.res.render (/app/node_modules/express/lib/response.js:753:7)
at /app/server.js:24:16
at callbacks (/app/node_modules/express/lib/router/index.js:161:37)
at param (/app/node_modules/express/lib/router/index.js:135:11)
at pass (/app/node_modules/express/lib/router/index.js:142:5)
at Router._dispatch (/app/node_modules/express/lib/router/index.js:170:5)
at Object.router (/app/node_modules/express/lib/router/index.js:33:10)
at next (/app/node_modules/express/node_modules/connect/lib/proto.js:199:15)
at store.get.next (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:309:9)
在我的服务器文件中:
express = require 'express'
app = express()
app.configure () ->
app.set 'views', __dirname + '/views'
app.set 'view engine', 'jade'
app.use express.logger('dev')
app.use express.bodyParser()
app.use express.methodOverride()
app.use express.cookieParser()
app.use express.session(
secret: 'WTF'
)
app.use app.router
app.use express['static'](process.cwd() + '/public')
app.get '/', (req, res) ->
res.render 'index'
app.get '/nested', (req, res) ->
res.render 'nested/index'
port = process.env.PORT || 3000
app.listen port, () ->
console.log 'Server started on ' + port + '\nPress CTRL-C to stop server.'
在本地,我不需要指定app.set 'views', __dirname + '/views'
服务器来运行和查找文件——不管有没有这个,它都不能在 Heroku 上工作。