Egg: hackerNews api国内被墙

Created on 13 Sep 2017  ·  17Comments  ·  Source: eggjs/egg

  • Node Version:
  • Egg Version:
  • Plugin Name:
  • Plugin Version:
  • Platform:
  • Mini Showcase Repository:


创建例子时 发生如下错误:
nodejs.ConnectionTimeoutError: Connect timeout for 5000ms, GET https://hacker-news.firebaseio.com/v0/topstories.json -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":1,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{},"requests":{}})
headers: {}
headers: {}

api名称:https://hacker-news.firebaseio.com/v0
ping请求过为unknown host

image

invalid

Most helpful comment

// config.local.js
module.exports = () => {
  const config = {};

  // add http_proxy to httpclient
  if (process.env.http_proxy) {
    config.httpclient = {
      request: {
        enableProxy: true,
        rejectUnauthorized: false,
        proxy: process.env.http_proxy,
      },
    };
  }

  return config;
}
$ http_proxy=http://127.0.0.1:8888 npm run dev

All 17 comments

你被墙了.

发现不是API的问题。。。测试过https://github.com/HackerNews/API 上面的api都可以获取json,hackerNews那个example例子的api请求超时,确定是被墙的问题吗?我已经翻墙了的

➜  vscode-test curl -I https://hacker-news.firebaseio.com/v0/topstories.json
HTTP/1.1 405 Method Not Allowed
Server: nginx
Date: Wed, 13 Sep 2017 07:01:41 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 43
Connection: keep-alive
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Strict-Transport-Security: max-age=31556926; includeSubDomains; preload

ping https://hacker-news.firebaseio.com 你写错地址了

我知道你想说我域名问题,但egg-examples/hackerNews 项目请求的api仍然超时
api是https://hacker-news.firebaseio.com/v0/topstories.json?orderBy=%22%24key%22&startAt=%220%22&endAt=%2229%22

运行后我的报错信息如下:
nodejs.ConnectionTimeoutError: Connect timeout for 30000ms, GET https://hacker-news.firebaseio.com/v0/topstories.json -2 (connected: false, keepalive socket: false, agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":1,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{},"requests":{}})
headers: {}
headers: {}
at Timeout._onTimeout (/Users//Desktop//egg/examples-master/hackernews/node_modules/urllib/lib/urllib.js:730:15)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
name: 'ConnectionTimeoutError'
requestId: 1
data: undefined
path: '/v0/topstories.json?orderBy=%22%24key%22&startAt=%220%22&endAt=%2229%22'
status: -2
headers: {}
res: { status: -2, statusCode: -2, headers: {}, size: 0, aborted: false, rt: 30026, keepAliveSocket: false, data: undefined, requestUrls: [ 'https://hacker-news.firebaseio.com/v0/topstories.json' ], timing: null, remoteAddress: '35.201.97.85', remotePort: '' }
pid: 11809
hostname: *
**.local

是在运行的时候超时,API测试过有返回json

超时就是你被墙了啊

应该是了。。。

你好,请问你是怎么解决的?翻墙? @kanting

翻墙也不行啊这个。。。 翻墙后把url放浏览器里面可以返回,但是在项目里面还是不行啊。。。

自己 CURL 看看

你 chrome 翻墙没用... 是 node 去 http 请求的,要整个系统翻墙

后面有时间改为 github trending 示例好了,欢迎 PR

搞定了 谢谢

@atian25 Github 官方提供 trending 接口了?我找了好多,都是爬虫解析,然后返回数据,感觉这样的不稳定。

@lei40251 如何搞定的?分享下哈

这个curl整个系统翻墙也不行 @atian25

这个curl整个系统翻墙也不行 @atian25

export ALL_PROXY=socks5://127.0.0.1:1080

https://eggjs.org/zh-cn/core/httpclient.html#%E8%B0%83%E8%AF%95%E8%BE%85%E5%8A%A9

// config.local.js
module.exports = () => {
  const config = {};

  // add http_proxy to httpclient
  if (process.env.http_proxy) {
    config.httpclient = {
      request: {
        enableProxy: true,
        rejectUnauthorized: false,
        proxy: process.env.http_proxy,
      },
    };
  }

  return config;
}
$ http_proxy=http://127.0.0.1:8888 npm run dev
Was this page helpful?
0 / 5 - 0 ratings