nuxt/cli

Nuxt 3.7 nuxi dev with https does not set dev proxy header x-forwarded-proto to https

Opened this issue · 1 comments

After upgrading to Nuxt 3.7 URLs, generated from a backend proxied via the dev server, which is accessible via https, contain the wrong protocol ("http" instead of "https").

After some digging, it turned out that httpxy has a middleware which determines if the request came via https (hasEncryptedConnection(req) which evaluates req.connection.encrypted) and sets the x-forwarded-proto accordingly to either "http" or "https".

So far I wasn't able to find out why, but although the dev server is listening to https, the req, passed to the proxy middleware, doesn't seem to have a TLSSocket connection, hence isn't recognised to be encrypted, hence sets the wrong x-forwarded-proto header.

It worked just fine in Nuxt 3.6.

// nuxt.config.ts
export default defineNuxtConfig({
  nitro: {
    devProxy: {
      '/api/': {
        target: 'https://localhost:8000/api/',
        autoRewrite: true,
        changeOrigin: true,
        xfwd: true,
      }
  },
  devServer: {
    https: {
      key: './key.pem',
      cert: './cert.pem',
    },
  },
});
pi0 commented

I can confirm this issue too happens also in playground for wss url.

I am thinking to support it as a feature in unjs/httpxy