node.js - 如何在 Chrome 中强制出现 504 错误

标签 node.js http-status-code-504

如何在 Chrome 中强制显示 504 错误?

我们有一个 Node 应用程序,偶尔会收到 504 错误,我想对 504 错误进行一些错误处理。

最佳答案

将其复制到名为 server.js 的文件中,然后运行 ​​node server.js。如果您访问 http://localhost:8080 您将抛出 504 错误。

var http = require('http');
var fs = require('fs');

http.createServer(function (req, res) {
  console.log("Sending 504 error to client");
  res.writeHead(504, {'Content-Type': 'text/plain'});
  res.end();
}).listen(8080);
console.log("Server started on port 8080");

关于node.js - 如何在 Chrome 中强制出现 504 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35223685/

相关文章:

tomcat - 碧 Jade 报告服务器 : Long Running Reports: 504 Gateway Timeout Errors

php - LinkedIn Share API 'ugcPosts' 响应 504 PHP 网关超时(WordPress)

javascript - Knexjs 和 es6 Try/Catch 导致未处理的 promise 拒绝警告?

node.js - 错误: Cannot find module 'node-fetch'\nRequire stack:\n-/var/task IN AWS Lambda

node.js - 如何使用 NodeJS 替换 PDF 文件中的字符串?

javascript - 使用 Mocha 和 Node.js 对私有(private)函数进行单元测试

java - 查询时间较长导致504超时错误?

php - 504 网关超时媒体殿

node.js - 在 mocha 中使用 sinon 创建请求 stub