简体   繁体   English

Heroku ENOENT:由于错误的express.js路由,因此没有这样的文件或目录

[英]Heroku ENOENT: no such file or directory due to faulty express.js routing

I seen other people running into the same issue but I am starting to believe that I have a deeper issue with my express file setup since other solutions are not fixing it. 我看到其他人也遇到了同样的问题,但是我开始相信我的快速文件设置存在一个更深层次的问题,因为其他解决方案无法解决该问题。

The idea that I had was to have a main page and then add folders for each of my projects. 我当时的想法是拥有一个主页,然后为我的每个项目添加文件夹。 This is my folder structure: 这是我的文件夹结构:

在此处输入图片说明

And the code in the index.js is simply this: 而index.js中的代码就是这样的:

const express = require('express');
const app = express();


app.listen(process.env.PORT || 5000, function () {
  console.log('Example app listening on port 5000!')
})

app.get('/', function(req, res){
    res.sendFile(__dirname + '/index.html');
});

app.use(express.static('asteroid'));

app.get('/asteroid', function(req, res){
  res.sendFile(__dirname + '/asteroid/');
});

Now like many other question out there, the issue that I see in the log is "Error: ENOENT: no such file or directory, stat '/app/asteroid/index.html'" . 现在像其他许多问题一样,我在日志中看到的问题是"Error: ENOENT: no such file or directory, stat '/app/asteroid/index.html'" The app tries to go to /app and it can't find my files on there. 该应用程序尝试转到/app ,但在那里找不到我的文件。 I seem to be missing something simple. 我似乎缺少一些简单的东西。

Any idea what can be causing this in my case? 知道是什么导致我的情况吗? I tried { root: __dirname } , joining everything with path() , and placed __dirname everywhere with no luck. 我尝试了{ root: __dirname } ,将所有内容与path()结合在一起,并将__dirname放在__dirname地方都没有运气。

Looks like the file listing shows Asteroid uppercase. 看起来文件清单显示Asteroid大写。 Maybe try renaming it to be lowercase everywhere? 也许在任何地方都尝试将其重命名为小写? If you're using express static then you don't need routes for each file. 如果使用快速静态,则不需要每个文件的路由。 So maybe just use static or just use routes. 所以也许只使用静态或只使用路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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