// server.js const express = require('express'); const axios = require('axios'); const cors = require('cors'); // Import the cors middleware const app = express(); const port = process.env.PORT || 3000; // Enable CORS for your Neocities domain const corsOptions = { origin: 'yourusername.neocities.org', // Replace with your Neocities domain optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204 } app.use(cors(corsOptions)); app.get('/proxy', async (req, res) => { const targetUrl = req.query.url; if (!targetUrl) { return res.status(400).send('URL parameter is required'); } try { const response = await axios.get(targetUrl, { responseType: 'text' // Or 'stream' for large files }); res.set(response.headers); // Forward the headers from the target res.send(response.data); } catch (error) { console.error("Proxy error:", error); res.status(500).send('Proxy error'); } }); app.listen(port, () => { console.log(`Proxy server listening at http://localhost:${port}`); });