バグ解消法、お役立ち情報など

curl: (7) Failed to connect to type-script port XXXX: Connection refused の解消法(TypeScript)

image

はじめに

node.jsを用いたAPIの開発などでCurlを使用していると、下記のエラーに出くわすことがあります。

curl: (7) Failed to connect to type-script port XXXX: Connection refused

XXXX はポート番号)

正しいポートを指定しているはずなのに、なぜかうまくいかない際の解消法です。

結論

localhost 以外へアクセスする際は、ホストを指定しましょう!

Before

TypeScript
const start = async () => { try { await server.listen({ port: XXXX }) } catch (err) { server.log.error(err) process.exit(1) } } start() // curl: (7) Failed to connect to type-script port XXXX: Connection refused

After

TypeScript
const start = async () => { try { await server.listen({ port: XXXX, host: '0.0.0.0' }) // host を追記 } catch (err) { server.log.error(err) process.exit(1) } } start()

これでアクセスできるようになりました!

バグ解消法、お役立ち情報など