DEVTomatoCake / Pterodactyl-vsc

Pterodactyl server files in VS Code
https://open-vsx.org/extension/tomatocake/pterodactyl-vsc
MIT License
3 stars 0 forks source link
open-vsx ptero pterodactyl vsc-extension vsc-filesystem vscode-extension vscode-filesystem

Pterodactyl server files in VS Code

Usage

  1. Install the extension from the VS Code marketplace, Open VSX, as VSIX by building it yourself, or by downloading it from the releases page.
  2. Open the command palette (default: Ctrl + Shift + P) and run Pterodactyl: Connect to server.
  3. Enter the panel URL and your client (not application) API key from "Account Settings" -> "API Credentials" -> Enter description -> "Create".
  4. Select the server you want to edit the files of.
  5. Done!

Configuration

CORS Proxy

By default the extension uses the proxy URL https://pterodactyl-vsc.tomatocake.workers.dev/?url=. The proxy was created by me to circumvent CORS blocking requests to the panel.

There are several options available if you don't want to use the default proxy:

  1. Use your own proxy using the following worker code, e.g. by using the following Cloudflare Workers code:

    export default {
    async fetch(request) {
        if (request.method == "OPTIONS") return new Response(void 0, {
            status: 204,
            headers: {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Headers": "authorization, content-type, accept"
            }
        })
        if (request.method != "GET" && request.method != "POST") return new Response(void 0, {
            status: 405
        })
    
        const proxyUrl = new URL(request.url).searchParams.get("url")
        if (!proxyUrl) return new Response("Missing url param", { status: 400 })
    
        let res = await fetch(proxyUrl, request)
    
        if (request.headers.has("Origin")) {
            res = new Response(res.body, res)
            res.headers.set("Access-Control-Allow-Origin", "*")
            res.headers.set("Access-Control-Allow-Credentials", "true")
        }
    
        return res
    }
    }
  2. If you have access to the domain owning the panel, you can overwrite CORS headers to the panel's responses, e.g. using Cloudflares Transform Rules:

    [!CAUTION] This will allow any website to access the panel's API using the credentials of the user who's logged in to the panel. If possible, always replace * with the hostname of the website the extension is used on, e.g. vscode.dev.

  1. If you want to build the extension yourself and you're only using it locally in the VS Code Desktop app, you can disable the web build of it by removing the browser property in the package.json. This works because only web-enabled extensions have to use the JavaScript Fetch API, which is affected by CORS.

Credits