mirror of
https://github.com/gigirassy/plaster.git
synced 2024-12-23 18:39:07 +00:00
Create app.js
This commit is contained in:
parent
6ec185cfe7
commit
1a5c581f2e
38
app.js
Normal file
38
app.js
Normal file
@ -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}`);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user