i'm having error serving static views on heroku app. strangely, heroku seems append "app" front of static file paths, , i'm not sure why. path should "public/views/index.html."
i tried proposed solution stack, didn't seem work: node.js, can't open files. error: enoent, stat './path/to/file'
the requests server:
app.use(express.static(__dirname + '/public')); app.get('/', function (req, res) { res.sendfile(__dirname + '/public/views/index.html'); }); // profile page app.get('/profile', function (req, res) { // check current (logged-in) user req.currentuser(function (err, user) { // show profile if logged-in user if (user) { res.sendfile(__dirname + '/public/views/profile.html'); // redirect if no user logged in } else { res.redirect('/'); } }); }); does have idea why heroku append "app" paths?
all paths work correctly on local server. thanks!
this because global __dirname variable inside heroku set /app. use process.env.pwd instead of __dirname.
Comments
Post a Comment