Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat(next.config): enhance security headers and optimize cache control settings

CristianOlivera148156292c762
diff --git a/next.config.ts b/next.config.ts
index e9e19fb..642f205 100644
--- a/next.config.ts
+++ b/next.config.ts
@@ -1,33 +1,138 @@
import type { NextConfig } from "next";
-import createNextIntlPlugin from 'next-intl/plugin';
+import createNextIntlPlugin from "next-intl/plugin";
-const withNextIntl = createNextIntlPlugin('./i18n.ts');
+const withNextIntl = createNextIntlPlugin("./i18n.ts");
+
+const securityHeaders = [
+ { key: "Cross-Origin-Opener-Policy", value: "same-origin" },
+ { key: "Cross-Origin-Embedder-Policy", value: "unsafe-none" },
+ { key: "X-Content-Type-Options", value: "nosniff" },
+ { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
+ {
+ key: "Permissions-Policy",
+ value: "camera=(self), microphone=(self), display-capture=(self)",
+ },
+];
const nextConfig: NextConfig = {
+ poweredByHeader: false,
+ compress: true,
images: {
+ formats: ["image/avif", "image/webp"],
remotePatterns: [
{
protocol: "https",
hostname: "images.unsplash.com",
pathname: "/**",
},
- { protocol: 'https', hostname: 'pixabay.com', pathname: '/**' },
- { protocol: 'https', hostname: 'cdn.pixabay.com', pathname: '/**' },
- { protocol: 'https', hostname: 'images.pexels.com', pathname: '/**' },
- // Auth providers avatars
- { protocol: 'https', hostname: 'api.dicebear.com', pathname: '/**' },
- { protocol: 'https', hostname: 'avatars.githubusercontent.com', pathname: '/**' },
- { protocol: 'https', hostname: 'lh3.googleusercontent.com', pathname: '/**' },
- { protocol: 'https', hostname: 'static-cdn.jtvnw.net', pathname: '/**' },
+ { protocol: "https", hostname: "pixabay.com", pathname: "/**" },
+ { protocol: "https", hostname: "cdn.pixabay.com", pathname: "/**" },
+ { protocol: "https", hostname: "images.pexels.com", pathname: "/**" },
+ { protocol: "https", hostname: "api.dicebear.com", pathname: "/**" },
+ {
+ protocol: "https",
+ hostname: "avatars.githubusercontent.com",
+ pathname: "/**",
+ },
+ {
+ protocol: "https",
+ hostname: "lh3.googleusercontent.com",
+ pathname: "/**",
+ },
+ { protocol: "https", hostname: "static-cdn.jtvnw.net", pathname: "/**" },
],
},
- headers: async () => [{
- source: "/(.*)",
- headers: [
- { key: "Cross-Origin-Opener-Policy", value: "same-origin" },
- { key: "Cross-Origin-Embedder-Policy", value: "unsafe-none" },
- ],
- }]
+ headers: async () => [
+ {
+ source: "/images/:path*",
+ headers: [
+ {
+ key: "Cache-Control",
+ value: "public, max-age=31536000, immutable",
+ },
+ ],
+ },
+ {
+ source: "/svg/:path*",
+ headers: [
+ {
+ key: "Cache-Control",
+ value: "public, max-age=31536000, immutable",
+ },
+ ],
+ },
+ {
+ source: "/ffmpeg/:path*",
+ headers: [
+ {
+ key: "Cache-Control",
+ value: "public, max-age=31536000, immutable",
+ },
+ ],
+ },
+ {
+ source: "/models/:path*",
+ headers: [
+ {
+ key: "Cache-Control",
+ value: "public, max-age=31536000, immutable",
+ },
+ ],
+ },
+ {
+ source: "/hdri/:path*",
+ headers: [
+ {
+ key: "Cache-Control",
+ value: "public, max-age=31536000, immutable",
+ },
+ ],
+ },
+ {
+ source: "/videos/:path*",
+ headers: [
+ {
+ key: "Cache-Control",
+ value: "public, max-age=86400, stale-while-revalidate=604800",
+ },
+ ],
+ },
+ {
+ source: "/site.webmanifest",
+ headers: [
+ {
+ key: "Cache-Control",
+ value: "public, max-age=86400, stale-while-revalidate=604800",
+ },
+ ],
+ },
+ {
+ source: "/:locale(en|es|ru|ko)",
+ headers: [
+ ...securityHeaders,
+ {
+ key: "Cache-Control",
+ value:
+ "public, s-maxage=300, stale-while-revalidate=86400",
+ },
+ ],
+ },
+ {
+ source: "/:locale(en|es|ru|ko)/:path*",
+ headers: [
+ ...securityHeaders,
+ {
+ key: "Cache-Control",
+ value:
+ "public, s-maxage=60, stale-while-revalidate=3600",
+ },
+ ],
+ },
+ {
+ source: "/(.*)",
+ headers: securityHeaders,
+ },
+ ],
};
export default withNextIntl(nextConfig);