diff --git a/app/[store]/page.tsx b/app/[store]/page.tsx
new file mode 100644
index 00000000..ff34a94e
--- /dev/null
+++ b/app/[store]/page.tsx
@@ -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
No se encontró la tienda
+ }
+
+ return (
+
+
Tienda: {store}
+
+ )
+}
diff --git a/middleware.ts b/middleware.ts
index aa816b53..5a647796 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -8,6 +8,56 @@ import { handleCollectionOwnershipMiddleware } from './middlewares/ownership/col
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))
+ }
+
+ // 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')) {
+ 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 (
@@ -45,12 +95,5 @@ export async function middleware(request: NextRequest) {
}
export const config = {
- matcher: [
- '/subscription-success',
- '/account-settings',
- '/first-steps',
- '/my-store',
- '/login',
- '/store/:path*',
- ],
+ matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
}