简体   繁体   中英

Serve static file with express on Heroku

Here are my files organisation :

http://i.imgur.com/Wdx8mKf.png

And i would like to serve the file in vr/build in a static way with express on heroku.

here is my code in 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.

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() {});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM