diff --git a/app.js b/app.js index d25b4b7..6f27edb 100644 --- a/app.js +++ b/app.js @@ -6,19 +6,12 @@ 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' }); - } +// Route to fetch Pastebin raw text data using the Paste ID +app.get('/:pasteId', async (req, res) => { + const pasteId = req.params.pasteId; - // 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}`; - } + // Construct the raw Pastebin URL + const rawUrl = `https://pastebin.com/raw/${pasteId}`; try { const response = await fetch(rawUrl); @@ -26,9 +19,9 @@ app.get('/fetch-paste', async (req, res) => { throw new Error('Failed to fetch data from Pastebin'); } const text = await response.text(); - res.json({ text }); + res.send(`
${text}`); } catch (error) { - res.status(500).json({ error: error.message }); + res.status(500).send(`Error: ${error.message}`); } });