Update app.js

This commit is contained in:
nune 2024-12-18 16:56:52 -05:00 committed by GitHub
parent 5274eaaa4d
commit 4fe9b4b341
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

15
app.js
View File

@ -7,7 +7,7 @@ const PORT = process.env.PORT || 3000;
app.use(express.static('public')); app.use(express.static('public'));
// Route to fetch Pastebin raw text data using the Paste ID or URL // Route to fetch Pastebin raw text data using the Paste ID or URL
app.get('/:pasteId?', async (req, res) => { app.get('/:pasteId?', (req, res) => {
let rawUrl; let rawUrl;
// If the pasteId is provided directly in the URL (like /uxK7EPux) // If the pasteId is provided directly in the URL (like /uxK7EPux)
@ -30,17 +30,8 @@ app.get('/:pasteId?', async (req, res) => {
return res.status(400).json({ error: 'URL or Paste ID is required' }); return res.status(400).json({ error: 'URL or Paste ID is required' });
} }
try { // Perform the redirect to the raw Pastebin URL
const response = await fetch(rawUrl); res.redirect(rawUrl);
if (!response.ok) {
throw new Error('Failed to fetch data from Pastebin');
}
const text = await response.text();
res.setHeader('Content-Type', 'text/plain'); // Ensure it's treated as plain text
res.send(text); // Send raw text
} catch (error) {
res.status(500).json({ error: error.message });
}
}); });
// Start the server // Start the server