-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
711 lines (657 loc) · 25.8 KB
/
Copy pathserver.js
File metadata and controls
711 lines (657 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
import express from 'express';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import fetch from 'node-fetch';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
const PORT = process.env.PORT || 4503;
// Configuration
const CONFIG = {
HYGRAPH_ENDPOINT:
process.env.HYGRAPH_ENDPOINT ||
'https://eu-central-1.cdn.hygraph.com/content/YOUR_PROJECT_ID/master',
HYGRAPH_TOKEN: process.env.HYGRAPH_TOKEN || '',
PREVIEW_DEBUG: true,
HYGRAPH_STUDIO_URL: process.env.HYGRAPH_STUDIO_URL || undefined
};
// GraphQL queries
const GET_RECIPES_QUERY = `
query GetRecipes($first: Int) {
recipes(stage: DRAFT, first: $first, orderBy: createdAt_DESC) {
id
title
description {
text
html
}
slug
difficulty
prepTime
cookTime
servings
heroImage {
id
url
fileName
width
height
}
author {
id
name
bio {
text
}
specialty
profilePhoto {
id
url
width
height
}
}
categories {
id
name
slug
}
}
}
`;
const GET_RECIPE_BY_ID_QUERY = `
query GetRecipeById($id: ID!) {
recipe(where: { id: $id }, stage: DRAFT) {
id
title
description {
text
html
}
slug
difficulty
prepTime
cookTime
servings
heroImage {
id
url
fileName
width
height
}
author {
id
name
bio {
text
}
specialty
profilePhoto {
id
url
width
height
}
}
categories {
id
name
slug
}
ingredients {
id
quantity
unit
ingredient {
name
}
}
recipeSteps {
id
stepNumber
title
instruction {
text
html
}
estimatedTime
}
reviews {
id
rating
comment {
text
}
reviewerName
createdAt
}
nutrition {
id
calories
protein
carbohydrates
fat
fiber
sugar
sodium
}
gallery {
id
url
fileName
width
height
}
}
}
`;
// GraphQL request function
async function graphqlRequest(query, variables = {}) {
try {
const response = await fetch(CONFIG.HYGRAPH_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(CONFIG.HYGRAPH_TOKEN && { Authorization: `Bearer ${CONFIG.HYGRAPH_TOKEN}` }),
},
body: JSON.stringify({
query,
variables,
}),
});
const result = await response.json();
if (result.errors) {
throw new Error(result.errors[0]?.message || 'GraphQL Error');
}
return result.data;
} catch (error) {
console.error('GraphQL request failed:', error);
throw error;
}
}
// Serve static files (CSS, JS, images) - but not the root directory
app.use('/js', express.static(join(__dirname, 'js')));
app.use('/css', express.static(join(__dirname, 'css')));
app.use('/images', express.static(join(__dirname, 'images')));
// Favicon route to prevent 404 errors
app.get('/favicon.ico', (req, res) => {
res.status(204).end();
});
// Home page route
app.get('/', async (req, res) => {
try {
const data = await graphqlRequest(GET_RECIPES_QUERY, { first: 12 });
const recipes = data.recipes || [];
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Delicious Recipes - Hygraph Recipe Example</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
.recipe-card:hover .recipe-image {
transform: scale(1.05);
}
.recipe-image {
transition: transform 0.3s ease;
}
</style>
</head>
<body class="min-h-screen bg-gray-50">
<!-- Hero Section -->
<section class="bg-white border-b" data-hygraph-entry-id="homepage-hero">
<div class="max-w-6xl mx-auto px-6 py-16 text-center">
<h1 class="text-5xl font-bold text-gray-900 mb-6" data-hygraph-field-api-id="heroTitle">
Delicious Recipes
</h1>
<p class="text-xl text-gray-600 max-w-2xl mx-auto" data-hygraph-field-api-id="heroSubtitle">
Discover amazing recipes from around the world. Each one carefully crafted and tested for the perfect dining experience.
</p>
</div>
</section>
<!-- Recipes Grid -->
<main class="max-w-6xl mx-auto px-6 py-12">
<div class="mb-8">
<h2 class="text-3xl font-bold text-gray-900 mb-4" data-hygraph-entry-id="recipe-section" data-hygraph-field-api-id="sectionTitle">
Latest Recipes
</h2>
<p class="text-gray-600" data-hygraph-entry-id="recipe-section" data-hygraph-field-api-id="sectionDescription">
Browse our collection of tried and tested recipes
</p>
</div>
${recipes.length > 0 ? `
<div class="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
${recipes.map(recipe => {
const categories = recipe.categories && recipe.categories.length > 0
? recipe.categories.map(category =>
`<span class="px-2 py-1 text-xs font-medium bg-blue-100 text-blue-800 rounded-full">
${category.name}
</span>`
).join('')
: '';
const heroImage = recipe.heroImage
? `<div class="aspect-video relative" data-hygraph-field-api-id="heroImage">
<img
src="${recipe.heroImage.url}"
alt="${recipe.title}"
class="w-full h-full object-cover recipe-image"
loading="lazy"
/>
</div>`
: '';
const prepTime = recipe.prepTime ? `<span data-hygraph-field-api-id="prepTime">⏱️ ${recipe.prepTime}min</span>` : '';
const difficulty = recipe.difficulty ? `<span data-hygraph-field-api-id="difficulty">📊 ${recipe.difficulty}</span>` : '';
const servings = recipe.servings ? `<span data-hygraph-field-api-id="servings">🍽️ ${recipe.servings}</span>` : '';
const metaItems = [prepTime, difficulty, servings].filter(item => item).join('');
const authorSection = recipe.author
? `<div class="flex items-center space-x-2" data-hygraph-field-api-id="author">
${recipe.author.profilePhoto
? `<img
src="${recipe.author.profilePhoto.url}"
alt="${recipe.author.name}"
class="w-6 h-6 rounded-full"
loading="lazy"
/>`
: ''
}
<span class="text-gray-700 font-medium">${recipe.author.name}</span>
</div>`
: '';
return `
<a href="/recipes/${recipe.id}" class="group block">
<article
class="bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition-shadow group-hover:shadow-xl recipe-card"
data-hygraph-entry-id="${recipe.id}"
>
${heroImage}
<div class="p-6">
<div class="mb-4">
${categories ? `<div class="flex flex-wrap gap-2 mb-3" data-hygraph-field-api-id="categories">${categories}</div>` : ''}
<h3 class="text-xl font-semibold text-gray-900 mb-2 group-hover:text-blue-600 transition-colors" data-hygraph-field-api-id="title">
${recipe.title}
</h3>
<p class="text-gray-600 text-sm leading-relaxed mb-4" data-hygraph-field-api-id="description">
${recipe.description.text}
</p>
</div>
${metaItems || authorSection ? `
<div class="flex items-center justify-between text-sm text-gray-500 border-t pt-4">
<div class="flex items-center space-x-4">
${metaItems}
</div>
${authorSection}
</div>
` : ''}
</div>
</article>
</a>
`;
}).join('')}
</div>
` : `
<div class="text-center py-12">
<p class="text-gray-500">No recipes found. Check your API connection.</p>
</div>
`}
</main>
<script src="/js/preview-sdk.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
if (window.HygraphPreviewSDK && window.HygraphPreviewSDK.Preview) {
const preview = new window.HygraphPreviewSDK.Preview({
endpoint: '${CONFIG.HYGRAPH_ENDPOINT}',
debug: ${CONFIG.PREVIEW_DEBUG},
studioUrl: '${CONFIG.HYGRAPH_STUDIO_URL}',
overlayEnabled: true
});
console.log('Live Preview initialized', preview.getVersion());
} else {
console.error('Live Preview not loaded');
}
});
</script>
</body>
</html>
`;
res.send(html);
} catch (error) {
console.error('Failed to load recipes:', error);
res.status(500).send('Error loading recipes');
}
});
// Recipe detail route
app.get('/recipes/:id', async (req, res) => {
try {
const { id } = req.params;
const data = await graphqlRequest(GET_RECIPE_BY_ID_QUERY, { id });
const recipe = data.recipe;
if (!recipe) {
return res.status(404).send('Recipe not found');
}
// Generate hero image section
const heroImage = recipe.heroImage
? `<div data-hygraph-field-api-id="heroImage">
<div class="aspect-[4/3] relative rounded-2xl overflow-hidden shadow-xl">
<img
src="${recipe.heroImage.url}"
alt="${recipe.title}"
class="w-full h-full object-cover"
loading="lazy"
/>
</div>
</div>`
: '';
// Generate recipe meta information
const metaItems = [
recipe.prepTime ? `<div class="text-center" data-hygraph-field-api-id="prepTime" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl mb-2 opacity-60">⏱️</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide mb-1">Prep Time</div>
<div class="text-xl font-light text-gray-900">${recipe.prepTime}min</div>
</div>` : '',
recipe.cookTime ? `<div class="text-center" data-hygraph-field-api-id="cookTime" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl mb-2 opacity-60">🔥</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide mb-1">Cook Time</div>
<div class="text-xl font-light text-gray-900">${recipe.cookTime}min</div>
</div>` : '',
recipe.servings ? `<div class="text-center" data-hygraph-field-api-id="servings" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl mb-2 opacity-60">🍽️</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide mb-1">Servings</div>
<div class="text-xl font-light text-gray-900">${recipe.servings}</div>
</div>` : '',
recipe.difficulty ? `<div class="text-center" data-hygraph-field-api-id="difficulty" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl mb-2 opacity-60">📊</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide mb-1">Difficulty</div>
<div class="text-xl font-light text-gray-900">${recipe.difficulty}</div>
</div>` : ''
].filter(item => item).join('');
// Generate categories section
const categories = recipe.categories && recipe.categories.length > 0
? `<div class="mb-8" data-hygraph-field-api-id="categories">
<div class="flex flex-wrap gap-3">
${recipe.categories.map(category =>
`<span class="px-4 py-2 text-sm font-medium bg-gray-100 text-gray-700 rounded-full hover:bg-gray-200 transition-colors duration-200">
${category.name}
</span>`
).join('')}
</div>
</div>`
: '';
// Generate ingredients section
const ingredients = recipe.ingredients && recipe.ingredients.length > 0
? `<div class="space-y-4" data-hygraph-entry-id="${recipe.id}" data-hygraph-field-api-id="ingredients">
${recipe.ingredients.map((ingredient) => {
const componentChain = JSON.stringify([{fieldApiId: 'ingredients', instanceId: ingredient.id}]);
return `<div class="group hover:bg-gray-50 rounded-xl p-4 transition-colors duration-200">
<div class="flex justify-between items-start">
<span class="font-medium text-gray-900 text-lg">${ingredient.ingredient.name}</span>
<div class="text-sm font-medium text-gray-500 ml-4">
<span
data-hygraph-entry-id="${recipe.id}"
data-hygraph-field-api-id="quantity"
data-hygraph-component-chain='${componentChain}'
>${ingredient.quantity}</span>
<span
data-hygraph-entry-id="${recipe.id}"
data-hygraph-field-api-id="unit"
data-hygraph-component-chain='${componentChain}'
>${ingredient.unit.toLowerCase()}</span>
</div>
</div>
</div>`;
}).join('')}
</div>`
: `<p class="text-gray-500 italic">No ingredients listed.</p>`;
// Generate recipe steps section
const recipeSteps = recipe.recipeSteps && recipe.recipeSteps.length > 0
? `<div class="space-y-8" data-hygraph-entry-id="${recipe.id}" data-hygraph-field-api-id="recipeSteps">
${recipe.recipeSteps.map((step) => {
const componentChain = JSON.stringify([{fieldApiId: 'recipeSteps', instanceId: step.id}]);
return `<div class="group">
<div class="flex items-start space-x-6">
<div
class="flex-shrink-0 w-12 h-12 bg-gradient-to-br from-gray-100 to-gray-200 text-gray-700 rounded-full flex items-center justify-center font-medium text-lg shadow-sm"
data-hygraph-entry-id="${recipe.id}"
data-hygraph-field-api-id="stepNumber"
data-hygraph-component-chain='${componentChain}'
>
${step.stepNumber}
</div>
<div class="flex-1 pt-1">
${step.title ? `<h3
class="text-xl font-medium text-gray-900 mb-3"
data-hygraph-entry-id="${recipe.id}"
data-hygraph-field-api-id="title"
data-hygraph-component-chain='${componentChain}'
>${step.title}</h3>` : ''}
<div
class="prose prose-lg prose-gray max-w-none text-gray-600 leading-relaxed"
data-hygraph-entry-id="${recipe.id}"
data-hygraph-field-api-id="instruction"
data-hygraph-component-chain='${componentChain}'
data-hygraph-rich-text-format="html"
>
${step.instruction.html}
</div>
${step.estimatedTime ? `
<div
class="inline-flex items-center mt-4 px-3 py-1 bg-gray-100 rounded-full text-sm font-medium text-gray-600"
data-hygraph-entry-id="${recipe.id}"
data-hygraph-field-api-id="estimatedTime"
data-hygraph-component-chain='${componentChain}'
>
<span class="mr-2 opacity-60">⏱️</span>
${step.estimatedTime} minutes
</div>
` : ''}
</div>
</div>
</div>`;
}).join('')}
</div>`
: `<p class="text-gray-500 italic">No instructions available.</p>`;
// Generate nutrition section
const nutrition = recipe.nutrition
? `<section class="mt-16 bg-gradient-to-r from-gray-50 to-white rounded-2xl p-8" data-hygraph-field-api-id="nutrition" data-hygraph-entry-id="${recipe.id}">
<h2 class="text-3xl font-light text-gray-900 mb-8">Nutrition Information</h2>
<div class="grid grid-cols-2 md:grid-cols-4 gap-6">
<div class="text-center" data-hygraph-field-api-id="nutrition.calories" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl font-light text-gray-900 mb-1">${recipe.nutrition.calories}</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide">Calories</div>
</div>
<div class="text-center" data-hygraph-field-api-id="nutrition.protein" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl font-light text-gray-900 mb-1">${recipe.nutrition.protein}g</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide">Protein</div>
</div>
<div class="text-center" data-hygraph-field-api-id="nutrition.carbohydrates" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl font-light text-gray-900 mb-1">${recipe.nutrition.carbohydrates}g</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide">Carbs</div>
</div>
<div class="text-center" data-hygraph-field-api-id="nutrition.fat" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl font-light text-gray-900 mb-1">${recipe.nutrition.fat}g</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide">Fat</div>
</div>
<div class="text-center" data-hygraph-field-api-id="nutrition.fiber" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl font-light text-gray-900 mb-1">${recipe.nutrition.fiber}g</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide">Fiber</div>
</div>
<div class="text-center" data-hygraph-field-api-id="nutrition.sugar" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl font-light text-gray-900 mb-1">${recipe.nutrition.sugar}g</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide">Sugar</div>
</div>
<div class="text-center" data-hygraph-field-api-id="nutrition.sodium" data-hygraph-entry-id="${recipe.id}">
<div class="text-3xl font-light text-gray-900 mb-1">${recipe.nutrition.sodium}mg</div>
<div class="text-sm font-medium text-gray-500 uppercase tracking-wide">Sodium</div>
</div>
</div>
</section>`
: '';
// Generate reviews section
const reviews = recipe.reviews && recipe.reviews.length > 0
? `<section class="mt-16" data-hygraph-field-api-id="reviews">
<h2 class="text-3xl font-light text-gray-900 mb-8">Reviews</h2>
<div class="space-y-8">
${recipe.reviews.map(review =>
`<div class="bg-gradient-to-r from-gray-50 to-white rounded-2xl p-6 hover:shadow-md transition-shadow duration-300">
<div class="flex items-start justify-between mb-4">
<h4 class="text-lg font-medium text-gray-900">${review.reviewerName}</h4>
<div class="flex items-center space-x-1">
${Array.from({ length: 5 }).map((_, i) =>
`<span class="text-lg ${i < review.rating ? 'text-yellow-400' : 'text-gray-300'}">⭐</span>`
).join('')}
</div>
</div>
<p class="text-gray-600 leading-relaxed mb-3">${review.comment.text}</p>
<p class="text-sm text-gray-400">
${new Date(review.createdAt).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})}
</p>
</div>`
).join('')}
</div>
</section>`
: '';
// Generate gallery section
const gallery = recipe.gallery && recipe.gallery.length > 0
? `<section class="mt-16" data-hygraph-field-api-id="gallery">
<h2 class="text-3xl font-light text-gray-900 mb-8">Photo Gallery</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
${recipe.gallery.map(image =>
`<div class="group aspect-square relative rounded-2xl overflow-hidden shadow-lg hover:shadow-xl transition-shadow duration-300" data-hygraph-entry-id="${recipe.id}" data-hygraph-field-api-id="gallery">
<img
src="${image.url}"
alt="${image.fileName}"
class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"
loading="lazy"
/>
</div>`
).join('')}
</div>
</section>`
: '';
// Generate author section
const author = recipe.author
? `<section class="mt-16 bg-gradient-to-r from-gray-50 to-white rounded-2xl p-8" data-hygraph-field-api-id="author">
<h2 class="text-3xl font-light text-gray-900 mb-8">About the Chef</h2>
<div class="flex items-start space-x-6">
${recipe.author.profilePhoto ? `
<div class="flex-shrink-0">
<img
src="${recipe.author.profilePhoto.url}"
alt="${recipe.author.name}"
class="w-20 h-20 rounded-full shadow-lg"
loading="lazy"
/>
</div>
` : ''}
<div>
<h3 class="text-2xl font-medium text-gray-900 mb-2">${recipe.author.name}</h3>
${recipe.author.specialty ? `<p class="text-gray-600 text-sm font-medium mb-3 uppercase tracking-wide">${recipe.author.specialty}</p>` : ''}
<p class="text-gray-600 leading-relaxed">${recipe.author.bio.text}</p>
</div>
</div>
</section>`
: '';
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${recipe.title} - Hygraph Recipe Example</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
.recipe-image {
transition: transform 0.3s ease;
}
</style>
</head>
<body class="min-h-screen bg-white">
<div class="min-h-screen bg-white">
<!-- Hero Section -->
<section class="bg-gradient-to-b from-gray-50 to-white">
<div class="max-w-6xl mx-auto px-6 py-16">
<div class="mb-8">
<a href="/" class="inline-flex items-center text-gray-600 hover:text-gray-900 transition-colors duration-200">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
Back to Recipes
</a>
</div>
<div class="grid lg:grid-cols-2 gap-12 items-start">
<!-- Hero Image -->
${heroImage}
<div class="lg:pl-8">
<h1 class="text-5xl font-light text-gray-900 mb-6 leading-tight" data-hygraph-field-api-id="title" data-hygraph-entry-id="${recipe.id}">
${recipe.title}
</h1>
<div class="prose prose-xl prose-gray mb-8 text-gray-600 leading-relaxed" data-hygraph-field-api-id="description" data-hygraph-entry-id="${recipe.id}">
${recipe.description.html}
</div>
<!-- Recipe Meta -->
${metaItems ? `<div class="grid grid-cols-2 md:grid-cols-4 gap-6 mb-8">${metaItems}</div>` : ''}
<!-- Categories -->
${categories}
</div>
</div>
</div>
</section>
<!-- Content -->
<main class="max-w-6xl mx-auto px-6 py-16">
<div class="grid lg:grid-cols-3 gap-16">
<!-- Ingredients -->
<div class="lg:col-span-1">
<h2 class="text-3xl font-light text-gray-900 mb-8">Ingredients</h2>
${ingredients}
</div>
<!-- Instructions -->
<div class="lg:col-span-2">
<h2 class="text-3xl font-light text-gray-900 mb-8">Instructions</h2>
${recipeSteps}
</div>
</div>
<!-- Nutrition Info -->
${nutrition}
<!-- Reviews -->
${reviews}
<!-- Gallery -->
${gallery}
<!-- Author -->
${author}
</main>
</div>
<script src="/js/preview-sdk.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
if (window.HygraphPreviewSDK && window.HygraphPreviewSDK.Preview) {
const preview = new window.HygraphPreviewSDK.Preview({
endpoint: '${CONFIG.HYGRAPH_ENDPOINT}',
debug: ${CONFIG.PREVIEW_DEBUG},
studioUrl: '${CONFIG.HYGRAPH_STUDIO_URL}',
overlayEnabled: true
});
console.log('Live Preview initialized', preview.getVersion());
} else {
console.error('Live Preview not loaded');
}
});
</script>
</body>
</html>
`;
res.send(html);
} catch (error) {
console.error('Failed to load recipe:', error);
res.status(500).send('Error loading recipe');
}
});
// Start server
app.listen(PORT, () => {
console.log(`Vanilla HTML Recipe App running on http://localhost:${PORT}`);
});