Protect your Next.js application with secure headers.
npm install -S @nosecone/next
Create a middleware.ts
file with the contents:
import { createMiddleware } from "@nosecone/next";
export const config = {
// matcher tells Next.js to run middleware on all routes
matcher: ["/(.*)"],
};
export default createMiddleware();
Add await connection()
in your app/layout.tsx
file:
+ import { connection } from "next/server";
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
+ // Opt-out of static generation for every page so the CSP nonce can be applied
+ await connection()
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
}
Licensed under the Apache License, Version 2.0.