From 2473c36fd128f55ed3f80c5ed742a94b31bb9739 Mon Sep 17 00:00:00 2001 From: Stivenjs Date: Wed, 4 Jun 2025 20:56:06 -0500 Subject: [PATCH 1/2] refactor(middleware): update hostname validation and redirect logic This commit refines the hostname validation process in the middleware by introducing a more robust check for main domains. It modifies the redirection logic to allow normal routing for valid main domains while maintaining the existing subdomain detection functionality. This enhances the clarity and maintainability of the code. --- middleware.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/middleware.ts b/middleware.ts index 5a647796..9395201b 100644 --- a/middleware.ts +++ b/middleware.ts @@ -14,19 +14,20 @@ export async function middleware(request: NextRequest) { const isProduction = process.env.NODE_ENV === 'production' const allowedDomains = isProduction ? ['fasttify.com'] : ['localhost'] - const isValidHostname = allowedDomains.some( - domain => hostname === domain || hostname.endsWith(`.${domain}`) - ) - // Si el hostname es válido, redirigir a la landing + const isMainDomain = allowedDomains.some(domain => { + const cleanHostname = hostname.split(':')[0] + return cleanHostname === domain || cleanHostname === `www.${domain}` + }) - if (isValidHostname) { - return NextResponse.redirect(new URL('/', request.url)) + // Si estamos accediendo al dominio principal, continuar con la ruta normal + if (isMainDomain) { + return NextResponse.next() } // Detectar subdominios const extractSubdomain = (hostname: string, isProduction: boolean): string => { - const cleanHostname = hostname.split(':')[0] // Remove port if present + const cleanHostname = hostname.split(':')[0] const parts = cleanHostname.split('.') if (isProduction) { // En producción: verificar si hay un subdominio (ej: tienda.fasttify.com) From 7e7c8d82b638bfa54af1c7aadbe50de14539ff23 Mon Sep 17 00:00:00 2001 From: Stivenjs Date: Wed, 4 Jun 2025 21:03:29 -0500 Subject: [PATCH 2/2] chore(amplify): update npm ci command and modify husky setup for production This commit updates the npm ci command to include development dependencies and adds an echo command to skip husky setup in production. Additionally, it modifies the prepare and postinstall scripts in package.json to conditionally run husky only if not in a production environment, enhancing the build process. --- amplify.yml | 3 ++- package.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/amplify.yml b/amplify.yml index 45e88eac..34174f9e 100644 --- a/amplify.yml +++ b/amplify.yml @@ -15,7 +15,8 @@ frontend: preBuild: commands: - nvm use 22 - - npm ci + - npm ci --include=dev + - echo "Skipping husky setup in production" build: commands: - npm run build diff --git a/package.json b/package.json index 5afdbe72..665c6dc7 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "build": "next build", "start": "next start", "lint": "next lint", - "prepare": "husky", + "prepare": "if command -v husky >/dev/null 2>&1; then husky; fi", + "postinstall": "if [ \"$NODE_ENV\" != \"production\" ] && command -v husky >/dev/null 2>&1; then husky; fi", "test": "jest", "test:watch": "jest --watch", "test:coverage": "jest --coverage"