如何使用express over cloudfoundry提供静态文件? 我试图使用以下代码:
app.use(express.static(__dirname+'/www'));
但是当我访问特定网址时,我得到了一些奇怪的例外:
TypeError: Object #<SendStream> has no method 'on'
at Object.static [as handle] (/var/vcap/data/dea/apps/FeedBack-0-c812c99aa3818946dd0bcf5538e2aecd/app/node_modules/express/node_modules/connect/lib/middleware/static.js:75:8)
at next (/var/vcap/data/dea/apps/FeedBack-0-c812c99aa3818946dd0bcf5538e2aecd/app/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.expressInit [as handle] (/var/vcap/data/dea/apps/FeedBack-0-c812c99aa3818946dd0bcf5538e2aecd/app/node_modules/express/lib/middleware.js:31:5)
at next (/var/vcap/data/dea/apps/FeedBack-0-c812c99aa3818946dd0bcf5538e2aecd/app/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.query [as handle] (/var/vcap/data/dea/apps/FeedBack-0-c812c99aa3818946dd0bcf5538e2aecd/app/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)
at next (/var/vcap/data/dea/apps/FeedBack-0-c812c99aa3818946dd0bcf5538e2aecd/app/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Function.handle (/var/vcap/data/dea/apps/FeedBack-0-c812c99aa3818946dd0bcf5538e2aecd/app/node_modules/express/node_modules/connect/lib/proto.js:198:3)
at Server.app (/var/vcap/data/dea/apps/FeedBack-0-c812c99aa3818946dd0bcf5538e2aecd/app/node_modules/express/node_modules/connect/lib/connect.js:66:31)
at Server.emit (events.js:67:17)
at HTTPParser.onIncoming (http.js:1134:12)
答案 0 :(得分:4)
我也犯了这个错误,我找到了答案; 你可以这样做:
第一
vmc delete yourapp
第二vmc push yourapp --runtime node08
也许您在第一次将应用程序推送到云时选择了Node运行时(node04,node06)的错误代码,并且服务器会记住您的选择。
答案 1 :(得分:1)
这应该有效,如果您创建模板快速应用程序,它将配置为从./public文件夹提供静态资产。确保您的配置是这样的;
var app = express();
app.configure(function(){
app.set('port', process.env.VCAP_APP_PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
如果您愿意,我可以尝试自行部署您的资源,看看我是否可以让它工作。