2

我正在使用 heroku 来托管 nodejs 应用程序。test我用这样的文件树推送一个文件夹名称:

-test
    /-server.js
    /-Procfile
    /-package.json
    /-public
        /-index.html
        /-style.css
        /script.js

我在 server.js 文件中处理请求,如下所示:

fa.readFile(__dirname + '/public/index.html', function(error, data) {
    if (error) {
        res.writeHead(500, {'Content-type':'text/plain'});
        res.end(error);
    } else {
        res.writeHead(200, {'Content-type':'text/html'});
        res.end(data);
    }
});

当我测试这个东西时,它想出了这个: ENOENT, open '/app/public/index.html' 我不知道它为什么引用/app文件夹。我在本地对其进行了测试,它返回没有css和js的纯html页面。

4

1 回答 1

1

您需要将项目结构下移一级。

您应该将test目录的内容推送为您的应用程序,而不是包含test应用程序目录的存储库。

-server.js
-Procfile
-package.json
-public
  /-index.html
  /-style.css
  /script.js
于 2013-09-12T03:08:30.663 回答