next-ssl-redirect-middleware
Advanced tools
Comparing version 0.1.4 to 0.1.5
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); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15623
7
132