-
Notifications
You must be signed in to change notification settings - Fork 3
Templates engine #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Templates engine #67
Changes from all commits
bc9b940
742105b
584f552
a1e68ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // 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 const config = { | ||||||||||||||||||||||||||||||||||||||||
| matcher: [ | ||||||||||||||||||||||||||||||||||||||||
| '/subscription-success', | ||||||||||||||||||||||||||||||||||||||||
| '/account-settings', | ||||||||||||||||||||||||||||||||||||||||
| '/first-steps', | ||||||||||||||||||||||||||||||||||||||||
| '/my-store', | ||||||||||||||||||||||||||||||||||||||||
| '/login', | ||||||||||||||||||||||||||||||||||||||||
| '/store/:path*', | ||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||
| matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'], | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
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:
🤖 Prompt for AI Agents