Skip to content

Conversation

@spitfire55
Copy link

What?

This PR adds a new secure option to the rewrites configuration, specifically for external rewrites (those with destination starting with http:// or https://). This option allows developers to control whether the proxy should verify SSL certificates when proxying requests to external destinations.

Why?

This change addresses a long-standing issue where Next.js users couldn't proxy to servers with self-signed certificates in development environments. The original issue #48117 and subsequent discussion #49546 highlight this need, where developers working with local development servers using self-signed certificates were unable to use Next.js's rewrite functionality.

How?

  1. Added a new secure field to the Rewrite type in multiple locations:

    • next-core/src/next_config.rs
    • packages/next/src/lib/load-custom-routes.ts
    • packages/next/src/server/config-schema.ts
  2. Updated the proxy request handling to respect this option:

    • Modified proxyRequest function to accept the secure parameter
    • Updated route resolution to pass through the secure option
    • Added proper type definitions and schema validation
  3. Added comprehensive documentation:

    • Updated the rewrites documentation with the new option
    • Added examples showing both secure and insecure configurations
    • Clarified that this option only applies to external rewrites

Example Usage

// next.config.js
module.exports = {
  async rewrites() {
    return [
      {
        source: '/api/:path*',
        destination: 'https://localhost:3001/:path*',
        secure: false, // Allow proxying to self-signed cert
      },
    ]
  },
}

Fixes #48117
Fixes #49546

@ijjk ijjk added Documentation Related to Next.js' official documentation. Turbopack Related to Turbopack with Next.js. type: next labels Apr 26, 2025
@changeset-bot
Copy link

changeset-bot bot commented May 13, 2025

⚠️ No Changeset found

Latest commit: 4e878a8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Related to Next.js' official documentation. Turbopack Related to Turbopack with Next.js. type: next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't proxy to a server that uses a self-signed certificate

2 participants