404错误的文件找不到使用response.sendfile()?

我/博客和/后触发许多404没有发现错误在浏览器的控制台,可以在这里find即使blog.html和post.html都工作,如果我从我的文件资源pipe理器打开它! (我的脚本和CSS工作)

我在/ blog和/ post的api端点给了我这些错误,所以没有一个运行blog.html或post.html的脚本。 请注意,我平静的api的其余部分工作得很好。

Posts.html:

<html> <head> <link rel="stylesheet" href = "css/style.css" type="text/css"> </link> <link href="https://fonts.googleapis.com/css?family=Lato:300" rel="stylesheet"> </link> <script src="js/scripts.js"></script> <script type="text/javascript" src="jq/jq-datatables-min.js"></script> <script type="text/javascript" src="jq/jq1-12-4.js"></script> </head> <body width="100%" class="body"> <div class = "PostPane"> <form method = "post" action="/postEntry"> Title: <input type="text" name="Title" value="Test"><br> Month: <input type="text" name="Month" value="August"><br> Year: <input type="text" name="Year" value="2017"><br> Paragraph: <input type="text" name="Paragraph" value="Today I added a post method."><br> <input type="submit" value="Submit"> </form> </div> <div class = "DeletePane"> <form method = "post" action="/deleteEntry"> Num: <input type="number" name="Num" value = "9"><br> <input type="submit" value="Submit"> </form> </div> <p> </p> </body> </html> 

Blog.html:

  <html> <head> <link rel="stylesheet" href = "css/style.css" type="text/css"> </link> <link href="https://fonts.googleapis.com/css?family=Lato:300" rel="stylesheet"> </link> <script type="text/javascript" src="js/scripts.js"></script> <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script> </head> <body> <script> getEntriesArray (); </script> <div id="div1"> </div> </body> </html> 

节点:

 app.get('/post', function(req, res) { res.sendFile(path.join(__dirname, 'public/post.html')); }); app.get('/blog', function(req, res) { res.sendFile(path.join(__dirname, 'public/blog.html')); }); 

它看起来像目录是不正确的。 所以,它无法加载资源。 你可以尝试把它们放到相同的文件夹或尝试使用这样的相对path:

 <img src="picture.jpg"> : picture.jpg is located in the same folder as the current page <img src="images/picture.jpg"> : picture.jpg is located in the images folder located in the current folder <img src="/images/picture.jpg"> : picture.jpg is located in the images folder located at the root of the current web <img src="../picture.jpg"> : picture.jpg is located in the folder one level up from the current folder