Skip to content
Merged
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
15 changes: 14 additions & 1 deletion lib/store-renderer/services/template-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,40 @@ class TemplateLoader {
*/
public async loadTemplate(storeId: string, templatePath: string): Promise<string> {
try {
console.log(`[TemplateLoader] Loading template: ${templatePath} for store: ${storeId}`)
console.log(`[TemplateLoader] Environment: ${this.appEnv}`)
console.log(`[TemplateLoader] CloudFront domain: ${this.cloudFrontDomain}`)
console.log(`[TemplateLoader] Bucket name: ${this.bucketName}`)

// Verificar caché primero
const cached = this.getCachedTemplate(storeId, templatePath)
if (cached) {
console.log(`[TemplateLoader] Using cached template: ${templatePath}`)
return cached.content
}

let content: string

// En producción usar CloudFront, en desarrollo usar S3 directo
if (this.appEnv === 'production' && this.cloudFrontDomain) {
console.log(`[TemplateLoader] Loading from CloudFront...`)
content = await this.loadTemplateFromCloudFront(storeId, templatePath)
} else {
console.log(`[TemplateLoader] Loading from S3...`)
content = await this.loadTemplateFromS3(storeId, templatePath)
}

console.log(`[TemplateLoader] Template loaded successfully: ${templatePath}`)

// Guardar en caché
this.setCachedTemplate(storeId, templatePath, content)

return content
} catch (error) {
console.error(`Error loading template ${templatePath} for store ${storeId}:`, error)
console.error(
`[TemplateLoader] Error loading template ${templatePath} for store ${storeId}:`,
error
)

const templateError: TemplateError = {
type: 'TEMPLATE_NOT_FOUND',
Expand Down