开机自检超时;提取响应挂起



我正在尝试使用户通过使用 Fetch 向我的服务器按下按钮来将数据发送到我的网站,但请求不断超时,我收到此错误:

(index): POST https://www.temp.com:2000/api/folder net::ERR_CONNECTION_TIMED_OUT
(index):1 Uncaught (in promise) TypeError: Failed to fetch

我尝试在服务器端添加app.use(cors(((,但这并没有解决问题。关于我应该在哪里解决这个问题的任何想法?

网站上的代码片段:

var fd = new FormData();
fd.append('data',data);
fetch('https://temp.com:2000/api/folder',{
method: 'post',
mode: 'no-cors',
body: fd
});

服务器端代码:

var express = require('express');
var multer  = require('multer');
var app = express();
var fs = require('fs');
var upload = multer({ dest: __dirname + '/folder/' });
app.post('/api/folder', upload.single('data'), function (req, res) {
console.log(req.file);
// we are setting response status code to 200 OK and sending back an empty response
res.status(200).send();
});
app.listen(2000);

当浏览器等待接收响应时,您的服务器不会向客户端发送任何响应,因此它为您提供 net::ERR_CONNECTION_TIMED_OUT

添加一个简单的空响应,例如:

app.post('/api/folder', upload.single('data'), function (req, res) {
console.log(req.file);
// we are setting response status code to 200 OK and sending back an empty response
res.status(200).send();
});

最新更新