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

时间:2017-08-16 17:11:52

标签: javascript jquery json node.js express

我的/ blog和/ post在浏览器的控制台中触发了许多404未找到错误,可以找到here ,即使我从文件资源管理器中打开它也可以使用blog.html和post.html ! (我的脚本和CSS工作)

我的api端点/ blog和/ post给了我这些错误,因此没有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'));
});

1 个答案:

答案 0 :(得分:0)

看起来目录不正确。因此,它无法加载资源。 您可以尝试将它们放在同一个文件夹上或尝试使用这样的相对路径:

package dclFrazioni;

{$R *.res}
....
{$IMPLICITBUILD OFF}

requires
  rtl,
  vcl,
  Frazioni;

contains
  (units...);

end.
相关问题