[英]Serve static file with express on Heroku
Here are my files organisation : 这是我的文件组织:
And i would like to serve the file in vr/build in a static way with express on heroku. 我想用在heroku上的express以静态方式在vr / build中提供文件。
here is my code in app.js : 这是我在app.js中的代码:
var express = require('express');
var app = express();
var path = require('path');
var port = process.env.PORT || 8080;
process.env.PWD = process.cwd();
//app.use(express.static(__dirname)); // Current directory is root
app.use(express.static(path.join(process.env.PWD, 'vr/build'))); // "public" off of current is root
app.listen(port);
console.log('Listening on port 8080');
It works locally but doesn't seems to work on heroku i have a Cannot GET / error on heroku. 它在本地工作,但似乎无法在heroku上工作,但在heroku上却无法获取/错误。
If anyone have any idea 如果有人有任何想法
Thanks 谢谢
This should work in theory but unless you try it you'll never know. 从理论上讲,这应该可行,但是除非您尝试尝试,否则您永远不会知道。
app.use(express.static(process.env.PWD+"/build"));
app.get("/build",function() {});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.