Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-ssl-redirect-middleware

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-ssl-redirect-middleware - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

6

dist/index.d.ts
import { NextFetchEvent, NextRequest, NextResponse } from 'next/server';
declare type Environment = "production" | "development" | "other";
declare type Params = {
type Environment = "production" | "development" | "other";
type Params = {
environments?: Environment[];
status?: 301 | 302;
};
declare const middleware: ({ environments, status }: Params) => (req: NextRequest, ev: NextFetchEvent) => NextResponse;
declare const middleware: ({ environments, status }: Params) => (req: NextRequest, ev: NextFetchEvent) => NextResponse<unknown>;
export default middleware;

@@ -5,4 +5,5 @@ "use strict";

const middleware = ({ environments = ["production"], status = 301 }) => (req, ev) => {
var _a, _b;
const currentEnv = process.env.NODE_ENV;
if (environments.includes(currentEnv) && req.headers.get("x-forwarded-proto") !== "https") {
if (environments.includes(currentEnv) && !((_b = (_a = req.headers) === null || _a === void 0 ? void 0 : _a.get("x-forwarded-proto")) === null || _b === void 0 ? void 0 : _b.includes("https"))) {
const hostname = req.headers.get('host') || req.nextUrl.hostname;

@@ -9,0 +10,0 @@ return server_1.NextResponse.redirect(`https://${hostname}${req.nextUrl.pathname}`, status);

{
"name": "next-ssl-redirect-middleware",
"version": "0.1.4",
"version": "0.1.5",
"description": "Nextjs Middleware to redirect http to https",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -11,3 +11,3 @@ # next-ssl-redirect-middleware

Create a file `pages/_middleware.ts` (or `.js`) with the following:
Create a file `middleware.ts` (or `.js`) with the following:

@@ -14,0 +14,0 @@ ```typescript

@@ -16,3 +16,3 @@ import { NextFetchEvent, NextRequest, NextResponse } from 'next/server'

if (environments.includes(currentEnv) && req.headers.get("x-forwarded-proto") !== "https") {
if (environments.includes(currentEnv) && !req.headers?.get("x-forwarded-proto")?.includes("https")) {
const hostname = req.headers.get('host') || req.nextUrl.hostname;

@@ -19,0 +19,0 @@ return NextResponse.redirect(`https://${hostname}${req.nextUrl.pathname}`, status);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc