如何调试Ngrok没有通过节点模块启动



我正在开发一个使用Ngrok进行开发的应用程序。从控制台运行Ngrok有效:

ngrok http 3011

示出了";控制台UI";指示隧道已打开,并给我要使用的url。

现在我正在尝试设置一些东西,这样开发人员就不需要复制粘贴URL等。但最基本的用法对我来说失败了:

// prepare-server.ts
import ngrok from 'ngrok'
import config from '../config'
(async () => {
try{
const nwhUrl = await ngrok.connect({ addr: config.serverPort })
console.log(nwhUrl)
} catch(e) {
console.error('problem with ngrok:', e)
}
})()

给我(当作为ts-node src/prepare-server.ts运行时(:

problem with ngrok: NgrokClientError: 
at NgrokClient.request (<path to project>node_modulesngroksrcclient.js:39:23)
at processTicksAndRejections (internal/process/task_queues.js:97:5)  
at connectRetry (<path to project>node_modulesngrokindex.js:29:22) {
response: <ref *1> IncomingMessage {
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: false,
ended: true,
endEmitted: true,
reading: false,
sync: false,
needReadable: false,
emittedReadable: false,
readableListening: true,
resumeScheduled: false,
errorEmitted: false,
emitClose: true,
autoDestroy: false,
destroyed: false,
errored: false,
closed: false,
closeEmitted: false,
defaultEncoding: 'utf8',
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: false,
decoder: [StringDecoder],
encoding: 'utf8',
[Symbol(kPaused)]: null
},
_events: [Object: null prototype] {
end: [Array],
aborted: [Array],
error: [Array],
readable: [Array],
finish: [Function: onfinish],
close: [Function: onclose]
},
_eventsCount: 6,
_maxListeners: undefined,
socket: Socket {
connecting: false,
_hadError: false,
_parent: null,
_host: null,
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null,
parser: null,
_httpMessage: [ClientRequest],
_peername: [Object],
[Symbol(asyncId)]: 15,
[Symbol(kHandle)]: [TCP],
[Symbol(kSetNoDelay)]: false,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0
},
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers: {
'content-type': 'application/json',
date: 'Wed, 21 Jul 2021 10:14:40 GMT',
'content-length': '168',
connection: 'close'
},
rawHeaders: [
'Content-Type',
'application/json',
'Date',
'Wed, 21 Jul 2021 10:14:40 GMT',
'Content-Length',
'168',
'Connection',
'close'
],
trailers: {},
rawTrailers: [],
aborted: false,
upgrade: false,
url: 'http://127.0.0.1:4041/api/tunnels',
method: null,
statusCode: 503,
statusMessage: 'Service Unavailable',
client: Socket {
connecting: false,
_hadError: false,
_parent: null,
_host: null,
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null,
parser: null,
_httpMessage: [ClientRequest],
_peername: [Object],
[Symbol(asyncId)]: 15,
[Symbol(kHandle)]: [TCP],
[Symbol(kSetNoDelay)]: false,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0
},
_consuming: true,
_dumped: false,
req: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 10,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Socket],
_header: 'POST /api/tunnels HTTP/1.1rn' +
'user-agent: got (https://github.com/sindresorhus/got)rn' +    
'content-type: application/jsonrn' +
'accept: application/jsonrn' +
'content-length: 74rn' +
'accept-encoding: gzip, deflate, brrn' +
'Host: 127.0.0.1:4041rn' +
'Connection: closern' +
'rn',
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
method: 'POST',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/api/tunnels',
_ended: true,
res: [Circular *1],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
timings: [Object],
emit: [Function (anonymous)],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype],
[Symbol(reentry)]: true
},
timings: {
start: 1626862480674,
socket: 1626862480676,
lookup: 1626862480677,
connect: 1626862480677,
secureConnect: undefined,
upload: 1626862480677,
response: 1626862480678,
end: 1626862480680,
error: undefined,
abort: undefined,
phases: [Object]
},
emit: [Function (anonymous)],
requestUrl: 'http://127.0.0.1:4041/api/tunnels',
redirectUrls: [],
request: Request {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 16,
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: true,
requestInitialized: true,
redirects: [],
retryCount: 0,
_progressCallbacks: [],
write: [Function: onLockedWrite],
end: [Function: onLockedWrite],
options: [Object],
requestUrl: 'http://127.0.0.1:4041/api/tunnels',
_cannotHaveBody: false,
_noPipe: true,
[Symbol(kCapture)]: false,
[Symbol(downloadedSize)]: 168,
[Symbol(uploadedSize)]: 74,
[Symbol(serverResponsesPiped)]: Set(0) {},
[Symbol(stopReading)]: true,
[Symbol(triggerRead)]: false,
[Symbol(jobs)]: [],
[Symbol(body)]: '{"addr":3011,"proto":"http","name":"2fbfea07-1dc3-4d7b-acfc-20a68b755c10"}',
[Symbol(bodySize)]: 74,
[Symbol(cancelTimeouts)]: [Function: cancelTimeouts],
[Symbol(unproxyEvents)]: [Function (anonymous)],
[Symbol(request)]: [ClientRequest],
[Symbol(originalResponse)]: [Circular *1],
[Symbol(isFromCache)]: false,
[Symbol(responseSize)]: 168,
[Symbol(response)]: [Circular *1],
[Symbol(startedReading)]: true
},
isFromCache: false,
ip: '127.0.0.1',
retryCount: 0,
rawBody: <Buffer >,
body: '',
[Symbol(kCapture)]: false
},
body: ''
}

注意503服务不可用代码。如果CLI版本正常工作,情况如何?

有什么想法可以调试吗?我也尝试过这种不带选项的方法(await ngrok.connect()(,结果变化不大。这是一个绝对基本的例子(见文档(,所以我真的无法做更多的事情来简化代码,看起来像是关于Ngrok内部的东西。。。节点包为v4.0.1

PS这个问题可能是相关的或相同的。虽然我的问题发生在节点14.1.0上,但它不会发生在节点15.14.0上。

根据您提供的详细信息,这似乎是一个内部ngork错误,或者与某些特定节点版本不兼容。

尝试更新(有时甚至更旧!(版本的包和/或节点实际上并不太难,如果不能完全解决问题(就像在您的案例中发生的那样(,可能有助于阐明问题的性质。

如果更新没有解决问题,你能做的最好的事情就是在他们的Github回购上打开一个问题,因为这个问题在ngork内部工作中似乎已经足够深入,我预计不会有很多人能够提供帮助。

https://github.com/bubenshchykov/ngrok/issues

最新更新