caiosilva1221 commited on
Commit
b29ebec
·
verified ·
1 Parent(s): 3baac25

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +6 -13
server.js CHANGED
@@ -15,13 +15,6 @@ const ApiKey = process.env.OPENROUTER_API_KEY;
15
  const Model = process.env.OPENROUTER_MODEL;
16
  const ApiUrl = "https://openrouter.ai/api/v1";
17
 
18
- // ✅ Permitir uso em iframe e acesso CORS
19
- app.use((req, res, next) => {
20
- res.setHeader("X-Frame-Options", "ALLOWALL");
21
- res.setHeader("Access-Control-Allow-Origin", "*");
22
- next();
23
- });
24
-
25
  app.use(bodyParser.json());
26
  app.use(express.static(path.join(__dirname, "dist")));
27
 
@@ -43,13 +36,13 @@ app.post("/api/ask-ai", async (req, res) => {
43
  res.setHeader("Cache-Control", "no-cache");
44
  res.setHeader("Connection", "keep-alive");
45
 
46
- const systemPrompt = `ONLY USE HTML, CSS AND JAVASCRIPT. No explanations, ONLY CODE. If you want to use ICON make sure to import the library first. Try to create the best UI possible using TailwindCSS. If not possible, use custom CSS (remember to import <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script> in the head). ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE`;
47
 
48
  try {
49
- const response = await fetch(`${ApiUrl}/chat/completions`, {
50
  method: "POST",
51
  headers: {
52
- Authorization: `Bearer ${ApiKey}`,
53
  "Content-Type": "application/json",
54
  },
55
  body: JSON.stringify({
@@ -58,7 +51,7 @@ app.post("/api/ask-ai", async (req, res) => {
58
  messages: [
59
  { role: "system", content: systemPrompt },
60
  ...(previousPrompt ? [{ role: "user", content: previousPrompt }] : []),
61
- ...(html ? [{ role: "assistant", content: `The current code is: ${html}` }] : []),
62
  { role: "user", content: prompt },
63
  ],
64
  }),
@@ -114,5 +107,5 @@ app.get("*", (_req, res) => {
114
  });
115
 
116
  app.listen(PORT, () => {
117
- console.log(`✅ Server running on port ${PORT}`);
118
- });
 
15
  const Model = process.env.OPENROUTER_MODEL;
16
  const ApiUrl = "https://openrouter.ai/api/v1";
17
 
 
 
 
 
 
 
 
18
  app.use(bodyParser.json());
19
  app.use(express.static(path.join(__dirname, "dist")));
20
 
 
36
  res.setHeader("Cache-Control", "no-cache");
37
  res.setHeader("Connection", "keep-alive");
38
 
39
+ const systemPrompt = ONLY USE HTML, CSS AND JAVASCRIPT. No explanations, ONLY CODE. If you want to use ICON make sure to import the library first. Try to create the best UI possible using TailwindCSS. If not possible, use custom CSS (remember to import <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script> in the head). ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE;
40
 
41
  try {
42
+ const response = await fetch(${ApiUrl}/chat/completions, {
43
  method: "POST",
44
  headers: {
45
+ Authorization: Bearer ${ApiKey},
46
  "Content-Type": "application/json",
47
  },
48
  body: JSON.stringify({
 
51
  messages: [
52
  { role: "system", content: systemPrompt },
53
  ...(previousPrompt ? [{ role: "user", content: previousPrompt }] : []),
54
+ ...(html ? [{ role: "assistant", content: The current code is: ${html} }] : []),
55
  { role: "user", content: prompt },
56
  ],
57
  }),
 
107
  });
108
 
109
  app.listen(PORT, () => {
110
+ console.log(✅ Server running on port ${PORT});
111
+ });