victor HF Staff commited on
Commit
c80e5e1
·
1 Parent(s): 71d3ba8

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +14 -7
server.js CHANGED
@@ -402,31 +402,38 @@ function applyDiffs(originalHtml, aiResponseContent) {
402
  return currentHtml;
403
  }
404
 
405
-
406
  // --- Endpoint to Apply Diffs Server-Side ---
407
  app.post("/api/apply-diffs", (req, res) => {
408
  const { originalHtml, aiResponseContent } = req.body;
409
 
410
- if (typeof originalHtml !== 'string' || typeof aiResponseContent !== 'string') {
411
- return res.status(400).json({ ok: false, message: "Missing or invalid originalHtml or aiResponseContent." });
 
 
 
 
 
 
 
 
412
  }
413
 
414
  try {
415
  console.log("[Apply Diffs] Received request to apply diffs.");
416
  const modifiedHtml = applyDiffs(originalHtml, aiResponseContent);
417
  console.log("[Apply Diffs] Diffs applied successfully.");
418
- res.setHeader('Content-Type', 'text/html; charset=utf-8');
419
  res.status(200).send(modifiedHtml);
420
  } catch (error) {
421
  console.error("[Apply Diffs] Error applying diffs:", error);
422
- res.status(400).json({ // Use 400 for client-side correctable errors (bad diff format)
 
423
  ok: false,
424
  message: error.message || "Failed to apply AI suggestions.",
425
  });
426
  }
427
  });
428
 
429
-
430
  // --- AI Interaction Route ---
431
  app.post("/api/ask-ai", async (req, res) => {
432
  const { prompt, html, previousPrompt } = req.body;
@@ -464,7 +471,7 @@ app.post("/api/ask-ai", async (req, res) => {
464
  }
465
 
466
  // --- Define System Prompts ---
467
- const initialSystemPrompt = `ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. Also, try to ellaborate as much as you can, to create something unique. ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE.`;
468
 
469
  const followUpSystemPrompt = `You are an expert web developer modifying an existing HTML file.
470
  The user wants to apply changes based on their request.
 
402
  return currentHtml;
403
  }
404
 
 
405
  // --- Endpoint to Apply Diffs Server-Side ---
406
  app.post("/api/apply-diffs", (req, res) => {
407
  const { originalHtml, aiResponseContent } = req.body;
408
 
409
+ if (
410
+ typeof originalHtml !== "string" ||
411
+ typeof aiResponseContent !== "string"
412
+ ) {
413
+ return res
414
+ .status(400)
415
+ .json({
416
+ ok: false,
417
+ message: "Missing or invalid originalHtml or aiResponseContent.",
418
+ });
419
  }
420
 
421
  try {
422
  console.log("[Apply Diffs] Received request to apply diffs.");
423
  const modifiedHtml = applyDiffs(originalHtml, aiResponseContent);
424
  console.log("[Apply Diffs] Diffs applied successfully.");
425
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
426
  res.status(200).send(modifiedHtml);
427
  } catch (error) {
428
  console.error("[Apply Diffs] Error applying diffs:", error);
429
+ res.status(400).json({
430
+ // Use 400 for client-side correctable errors (bad diff format)
431
  ok: false,
432
  message: error.message || "Failed to apply AI suggestions.",
433
  });
434
  }
435
  });
436
 
 
437
  // --- AI Interaction Route ---
438
  app.post("/api/ask-ai", async (req, res) => {
439
  const { prompt, html, previousPrompt } = req.body;
 
471
  }
472
 
473
  // --- Define System Prompts ---
474
+ const initialSystemPrompt = `ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. Also, try to ellaborate as much as you can, to create something unique. If needed you are allowed to use tailwincss (if so make sure to import <script src="https://cdn.tailwindcss.com"></script> in the head). ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE.`;
475
 
476
  const followUpSystemPrompt = `You are an expert web developer modifying an existing HTML file.
477
  The user wants to apply changes based on their request.