bratgen / index.js
FarelDeveloper's picture
Update index.js
68a551a verified
Raw
History Blame Contribute Delete
1.75 kB
const express = require("express");
const brat = require("brat-farel"); // FIX DI SINI
const app = express();
const PORT = process.env.PORT || 7860;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
/*
====================================
WEB PAGE
====================================
*/
app.get("/", (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Brat Generator - Farel</title>
<style>
body {
font-family: Arial;
background: #0f172a;
color: white;
text-align: center;
padding: 50px;
}
input {
padding: 10px;
width: 300px;
border-radius: 8px;
border: none;
}
button {
padding: 10px 20px;
border-radius: 8px;
border: none;
background: #3b82f6;
color: white;
cursor: pointer;
}
</style>
</head>
<body>
<h1>🔥 Brat Generator</h1>
<form action="/generate" method="GET">
<input type="text" name="text" placeholder="Masukkan teks..." required />
<br><br>
<button type="submit">Generate</button>
</form>
</body>
</html>
`);
});
/*
====================================
API GENERATE
====================================
*/
app.get("/generate", async (req, res) => {
try {
const text = req.query.text;
if (!text) return res.send("Teks tidak boleh kosong");
const imageBuffer = await brat(text);
res.setHeader("Content-Type", "image/png");
res.send(imageBuffer);
} catch (err) {
console.error(err);
res.status(500).send("Terjadi kesalahan saat generate brat.");
}
});
app.listen(PORT, "0.0.0.0", () => {
console.log(`Server berjalan di port ${PORT}`);
});