【问题标题】:Node.js http-server custom error messageNode.js http-server 自定义错误信息
【发布时间】:2017-10-03 14:12:57
【问题描述】:

我启动了一个 node.js http-server - "https://www.npmjs.com/package/http-server" 如果我在目录中键入一个不存在的文件,我会得到浏览器消息:

This localhost page can’t be found

No webpage was found for the web address: http://localhost:8080/foo
Search Google for localhost 8080 foo
HTTP ERROR 404

我的问题: 我可以以某种方式自定义此错误消息吗?

【问题讨论】:

    标签: node.js http simplehttpserver


    【解决方案1】:

    在您的public 目录中创建404.html 文件并将您想要显示的内容放入该文件中

    示例

    命令行

    # http-server ./public/

    ./public/404.html的内容

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>404</title>
    </head>
    <body>
    <p>My custom 404 message</p>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 1970-01-01
      • 2018-04-03
      • 2017-01-28
      • 2021-02-10
      相关资源
      最近更新 更多