私はいくつかのリクエストをHeroku APIに転送する必要があるNodeJS/expressアプリケーションを構築しています。Heroku用NodeJS Proxy Server
私は多くの異なるソリューション(this SO questionを含む)を調査しましたが、どれも私のためには機能していません。
コード:
const API_SERVER = 'https://my-api.herokuapp.com';
const path = require('path'),
fs = require('fs'),
express = require('express'),
router = express.Router(),
httpProxy = require('http-proxy'),
apiProxy = httpProxy.createProxyServer({
target: API_SERVER,
secure: true,
ssl: {
key: fs.readFileSync(path.join('ssl', 'key.pem'),'utf8'),
cert: fs.readFileSync(path.join('ssl', 'cert.pem'), 'utf8')
}
});
router.all('/api/*', (req, res) => {
apiProxy.web(req, res);
});
module.exports = router;
マイ特急サーバーは正常に機能しますが、私はlocalhost/api/some-route
に要求を行うとき、私は次のエラーを取得:私はそのエラー・メッセージ、Herokuのに集めることができるものから、
Error: Hostname/IP doesn't match certificate's altnames: "Host: localhost. is not in the cert's altnames: DNS:*.herokuapp.com, DNS:herokuapp.com"
at Object.checkServerIdentity (tls.js:199:17)
at TLSSocket.<anonymous> (_tls_wrap.js:1091:29)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket._finishInit (_tls_wrap.js:603:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:433:38)
Details:
killed: false
code: 1
signal: null
cmd: node ./server/index.js
Stack:
Error: Command failed: node ./server/index.js
C:\Users\web-app\node_modules\http-proxy\lib\http-proxy\index.js:119
throw err;
^
Error: Hostname/IP doesn't match certificate's altnames: "Host: localhost. is not in the cert's altnames: DNS:*.herokuapp.com, DNS:herokuapp.com"
at Object.checkServerIdentity (tls.js:199:17)
at TLSSocket.<anonymous> (_tls_wrap.js:1091:29)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket._finishInit (_tls_wrap.js:603:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:433:38)
at ChildProcess.exithandler (child_process.js:206:12)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:877:16)
at Socket.<anonymous> (internal/child_process.js:334:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:498:12)
を実際に私がローカルホストからプロキシをしているのが好きではないようです...しかし、私は本当に他に何を試していいのか分かりません。
私はhttpProxy.createProxyServer()
(上記の例のように、自己署名入りのSSL証明書を使用)とSSLを使用せずに作成しようとしましたが、同じエラーが発生します。