Deploy Nodejs on Heroku fails serving static files located in subfolders

前端 未结 6 1721
一整个雨季
一整个雨季 2020-11-30 12:30

I\'m deploying a NodeJs application using Heroku. Everything works fine except a little issue serving static files.

I have the following configuration



        
6条回答
  •  遥遥无期
    2020-11-30 12:49

    Apparently, as explain in this question: Heroku(Cedar) + Node + Express + Jade Client-side javascript files in subdirectory work locally with foreman+curl but not when pushed to Heroku, you can't use __dirname with Heroku.

    The alternative seems to be:

    // At the top of your web.js
    process.env.PWD = process.cwd()

    // Then
    app.use(express.static(process.env.PWD + '/htdocs'));

提交回复
热议问题