You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用VS Code Thunder Client访问localhost:3000时请求卡住求助

问题描述

我是后端新手,正在跟随codewithharry的React JS课程学习。操作与教程完全一致,但使用Thunder Client发送GET请求时一直卡在处理状态,然而用Chrome浏览器访问该链接却能正常工作。

VS Code Thunder Client截图

我的代码如下:

index.js

const connectDB = require('./db');
connectDB();
const express = require('express')
const app = express()
const port = 3000

app.use(express.json())
//Available routes
app.use('/api/auth', require('./routes/auth'))
app.use('/api/notes', require('./routes/notes'))

app.get('/', (req, res) => {
    res.send('Hello World!')
})

app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`)
})

db.js

const mongoose = require('mongoose');
const mongoURI = "mongodb://127.0.0.1:27017/inotebookdb"

const connectDB = async () => {
    try {
        await mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true });
        console.log("successfully connected");
    } catch (err) {
        console.log(err);
    }
}


module.exports = connectDB;
解决思路
  • 核对请求URL:确保Thunder Client里填写的URL和Chrome访问的完全一致,包括端口、路径,别出现多余空格或拼写错误。比如Chrome用http://localhost:3000/,Thunder Client里也保持相同格式。
  • 检查服务端日志:发送请求时盯着Node.js控制台,如果没收到请求日志,说明Thunder Client的请求没发出去,大概率是VS Code的代理或网络设置问题;如果收到请求但没响应,就得排查路由逻辑或数据库连接是否阻塞了响应。
  • 调整数据库连接时机:当前代码启动Express服务时,没有等待数据库连接完成就开始监听请求。如果你的接口(比如/api/auth或/api/notes)依赖数据库,可能因为连接未就绪导致请求挂起。修改启动逻辑,等数据库连接成功后再启动服务:
    const connectDB = require('./db');
    const express = require('express')
    const app = express()
    const port = 3000
    
    app.use(express.json())
    //Available routes
    app.use('/api/auth', require('./routes/auth'))
    app.use('/api/notes', require('./routes/notes'))
    
    app.get('/', (req, res) => {
        res.send('Hello World!')
    })
    
    // 等待数据库连接成功后启动服务
    connectDB().then(() => {
        app.listen(port, () => {
            console.log(`Example app listening at http://localhost:${port}`)
            console.log("数据库已连接");
        })
    }).catch(err => {
        console.error("数据库连接失败,无法启动服务", err);
    })
    
  • 禁用VS Code代理:打开VS Code设置,搜索http.proxy,如果有配置的话暂时禁用,再测试Thunder Client请求。
  • 重启工具:有时候Thunder Client或VS Code会出现进程缓存问题,重启后可能恢复正常。
  • 调整超时时间:在Thunder Client的设置里把请求超时时间调长(比如设为30秒),避免因为请求处理慢被工具判定为超时卡住。

内容的提问来源于stack exchange,提问作者Sahil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 04:43:30