From 1a5c581f2e951300e8a5937416626c1fd6bfb2cc Mon Sep 17 00:00:00 2001 From: nune <145225213+gigirassy@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:16:43 -0500 Subject: [PATCH] Create app.js --- app.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 app.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..d25b4b7 --- /dev/null +++ b/app.js @@ -0,0 +1,38 @@ +const express = require('express'); +const fetch = require('node-fetch'); + +const app = express(); +const PORT = process.env.PORT || 3000; + +app.use(express.static('public')); + +// Endpoint to fetch Pastebin raw text data +app.get('/fetch-paste', async (req, res) => { + const { url } = req.query; + if (!url) { + return res.status(400).json({ error: 'URL is required' }); + } + + // Check if the URL is a Pastebin URL and convert to raw format + let rawUrl = url; + if (url.includes('pastebin.com/') && !url.includes('/raw/')) { + const pasteId = url.split('/').pop(); + rawUrl = `https://pastebin.com/raw/${pasteId}`; + } + + try { + const response = await fetch(rawUrl); + if (!response.ok) { + throw new Error('Failed to fetch data from Pastebin'); + } + const text = await response.text(); + res.json({ text }); + } catch (error) { + res.status(500).json({ error: error.message }); + } +}); + +// Start the server +app.listen(PORT, () => { + console.log(`Server is running on http://localhost:${PORT}`); +});