Skip to content

CORS proxy

Planeson edited this page Apr 16, 2025 · 5 revisions

This is a guide on how to install a CORS proxy on a debian based system. If you are using something else, feel free to ask ChatGPT.

Step 1: install node.js
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

Verify the installation:
node -v
npm -v

Step 2: Create the Proxy Server
mkdir ~/cors-proxy
cd ~/cors-proxy
npm init -y
npm install express node-fetch@2 cors

Create the proxy file:
nano index.js

Paste this code:

const express = require('express');
const fetch = require('node-fetch');
const cors = require('cors');

const app = express();
const PORT = 3000;

app.use(cors());

app.get('/proxy', async (req, res) => {
    const targetUrl = req.query.url;
    if (!targetUrl) {
        return res.status(400).json({ error: 'Missing "url" query parameter.' });
    }

    try {
        const response = await fetch(targetUrl);
        const contentType = response.headers.get('content-type');
        res.setHeader('Content-Type', contentType);
        const body = await response.text();
        res.send(body);
    } catch (error) {
        res.status(500).json({ error: 'Failed to fetch target URL.', detail: error.message });
    }
});

app.listen(PORT, () => {
    console.log(`CORS proxy running at http://localhost:${PORT}`);
});

Step 3: run the proxy
node index.js

First run the proxy, then start the html.

Clone this wiki locally