最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

postgresql - Issue with WebSocket Proxy Configuration for Local Development in Next.js App - Stack Overflow

programmeradmin0浏览0评论

I am currently setting up a local development environment for a Next.js application. Following the instructions at , I have configured Docker containers for Postgres and WSProxy locally. I am attempting to connect to these services from the app running with npm run dev. However, I am encountering the following error:

Error fetching recipes: ErrorEvent {
  [Symbol(kTarget)]: WebSocket {
    _events: [Object: null prototype] {
      error: [Function],
      message: [Function],
      close: [Function],
      open: [Function]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    _binaryType: 'arraybuffer',
    _closeCode: 1006,
    _closeFrameReceived: false,
    _closeFrameSent: false,
    _closeMessage: <Buffer >,
    _closeTimer: null,
    _extensions: {},
    _paused: false,
    _protocol: '',
    _readyState: 3,
    _receiver: null,
    _sender: null,
    _socket: null,
    _bufferedAmount: 0,
    _isServer: false,
    _redirects: 0,
    _autoPong: true,
    _url: 'wss://localhost/v2',
    _req: null,
    [Symbol(shapeMode)]: false,
    [Symbol(kCapture)]: false
  },
  [Symbol(kType)]: 'error',
  [Symbol(kError)]: AggregateError [ECONNREFUSED]: 
      at internalConnectMultiple (node:net:1117:18)
      at afterConnectMultiple (node:net:1684:7)
      at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
    code: 'ECONNREFUSED',
    [errors]: [ [Error], [Error] ]
  },
  [Symbol(kMessage)]: ''
}

There are no logs displayed in the Postgres and WSProxy containers, indicating that the requests are not reaching them.

In the API route file, I checked the neonConfig settings as follows, and it appears that the settings from db.ts are being applied correctly:

export async function GET() {
  try {
    console.log('neonConfig settings:', {
      wsProxy: neonConfig.wsProxy,
      useSecureWebSocket: neonConfig.useSecureWebSocket,
      pipelineTLS: neonConfig.pipelineTLS,
      pipelineConnect: neonConfig.pipelineConnect,
    });

    console.log(neonConfig.wsProxy?.toString());

    const result = await sql.query(`SELECT id, ...`);
    ...

However, the error log shows _url: 'wss://localhost/v2'. Additionally, the documentation at .md?plain=1#L266 states the following:

#### `wsProxy: string | (host: string, port: number | string) => string`

If connecting to a non-Neon database, the `wsProxy` option should point to [your WebSocket proxy](DEPLOY.md). It can either be a string, which will have `?address=host:port` appended to it, or a function with the signature `(host: string, port: number | string) => string`. Either way, the protocol must _not_ be included, because this depends on other options. For example, when using the `wsproxy` proxy, the `wsProxy` option should look something like this:

Default: `host => host + '/v2'`.

Therefore, it seems that the wsProxy: neonConfig.wsProxy setting is not being applied correctly. Could you please provide guidance on how to resolve this issue?

Thank you for your assistance.

Best regards,

发布评论

评论列表(0)

  1. 暂无评论