Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/[store]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client'

import { useParams } from 'next/navigation'

export default function StorePage() {
const params = useParams()
const store = (params.store as string) || undefined

if (!store) {
return <div>No se encontró la tienda</div>
}

return (
<div>
<h1>Tienda: {store}</h1>
</div>
)
Comment on lines +13 to +17
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add proper page structure and metadata.

The current implementation is minimal. Consider adding proper HTML structure, metadata, and actual store content.

Would you like me to help implement a more complete store page component with:

  • Proper page title and metadata
  • Store details fetching
  • Loading states
  • Error boundaries
  • SEO optimization
🤖 Prompt for AI Agents
In app/[store]/page.tsx around lines 13 to 17, the current page component lacks
proper HTML structure, metadata, and meaningful store content. Enhance the
component by adding a head section with a descriptive page title and metadata
for SEO. Implement logic to fetch store details dynamically, include loading and
error states to handle asynchronous data fetching gracefully, and structure the
page content to display store information clearly. This will improve user
experience and SEO performance.

}
59 changes: 51 additions & 8 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,56 @@

export async function middleware(request: NextRequest) {
const path = request.nextUrl.pathname
const hostname = request.headers.get('host') || ''

// Configuración de dominios
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

if (isValidHostname) {
return NextResponse.redirect(new URL('/', request.url))
}
Comment on lines +17 to +25
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the inverted domain validation logic.

The current logic redirects to the root landing page when the hostname matches the main domain (fasttify.com or localhost), which appears to be inverted. This would prevent users from accessing the main site and only allow access via subdomains.

-  const isValidHostname = allowedDomains.some(
-    domain => hostname === domain || hostname.endsWith(`.${domain}`)
-  )
-
-  // Si el hostname es válido, redirigir a la landing
-
-  if (isValidHostname) {
-    return NextResponse.redirect(new URL('/', request.url))
-  }
+  // Check if hostname is main domain (without subdomain)
+  const isMainDomain = allowedDomains.some(domain => {
+    const cleanHostname = hostname.split(':')[0]
+    return cleanHostname === domain || cleanHostname === `www.${domain}`
+  })
+
+  // If accessing main domain, continue with normal routing
+  if (isMainDomain) {
+    return NextResponse.next()
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isValidHostname = allowedDomains.some(
domain => hostname === domain || hostname.endsWith(`.${domain}`)
)
// Si el hostname es válido, redirigir a la landing
if (isValidHostname) {
return NextResponse.redirect(new URL('/', request.url))
}
// Check if hostname is main domain (without subdomain)
const isMainDomain = allowedDomains.some(domain => {
const cleanHostname = hostname.split(':')[0]
return cleanHostname === domain || cleanHostname === `www.${domain}`
})
// If accessing main domain, continue with normal routing
if (isMainDomain) {
return NextResponse.next()
}
🤖 Prompt for AI Agents
In middleware.ts around lines 17 to 25, the domain validation logic is inverted,
causing redirection to the root landing page when the hostname matches the main
domain instead of subdomains. To fix this, reverse the condition so that
redirection happens only when the hostname is not the main domain or localhost,
allowing access to the main site and restricting subdomains as intended.


// Detectar subdominios
const extractSubdomain = (hostname: string, isProduction: boolean): string => {
const cleanHostname = hostname.split(':')[0] // Remove port if present
const parts = cleanHostname.split('.')
if (isProduction) {
// En producción: verificar si hay un subdominio (ej: tienda.fasttify.com)
if (parts.length > 2 && cleanHostname.endsWith('fasttify.com')) {
Comment thread Dismissed
return parts[0]
}
} else {
// En desarrollo: usar el formato subdominio.localhost:3000
if (parts.length > 1 && cleanHostname.endsWith('localhost')) {
return parts[0]
}
}
return ''
}
const subdomain = extractSubdomain(hostname, isProduction)

// Reescribir URLs basadas en subdominios
if (subdomain && subdomain !== 'www') {
const url = request.nextUrl.clone()
if (path === '/') {
// Si estamos en la raíz, reescribir a la ruta de la tienda
url.pathname = `/${subdomain}`
} else if (!path.startsWith(`/${subdomain}`)) {
// Si la ruta no empieza con el subdominio, agregar el prefijo
url.pathname = `/${subdomain}${path}`
} else {
// La ruta ya tiene el prefijo correcto
return NextResponse.next()
}
return NextResponse.rewrite(url)
}

// Verificar propiedad de productos específicos
if (
Expand Down Expand Up @@ -45,12 +95,5 @@
}

export const config = {
matcher: [
'/subscription-success',
'/account-settings',
'/first-steps',
'/my-store',
'/login',
'/store/:path*',
],
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
}