Skip to main content

@robojs/patch

Tired of platform-specific bugs? Was your project working fine until recently? @robojs/patch is here to save the day! 🎩✨

This package contains a collection of lightweight patches for common issues. We intend on maintaining them for as long as needed.

Not using Robo.js yet? That's okay! Most patches work with any JavaScript project.

➞ 📚 Documentation: Getting started

➞ 🚀 Community: Join our Discord server

Installation 💻​

To add this plugin to your Robo.js project:

npx robo add @robojs/patch

Or install it as a normal package if you're not using Robo.js:

npm install @robojs/patch

Patches 🩹​

Discord Proxy​

When running a Discord Activity through Discord, you may encounter Content Security Policy (CSP) issues. This patch fixes those issues, including Hot Module Replacement (HMR), by making sure internal requests follow Discord Proxy rules.

We have different ways to apply this patch depending on your project setup.

If you're using Vite, you can apply the patch as a plugin in your Vite config file.

import { DiscordProxy } from '@robojs/patch'
import { defineConfig } from 'vite'

export default defineConfig({
plugins: [DiscordProxy.Vite()]
})

[!TIP] You can find this file as /config/vite.mjs if you're using a Robo Template or vite.config.js if you're using something else.

We recommend this method because it allows the patch to run before before Vite's HMR client, ensuring that it works correctly.

Method 2: Function Call​

If you're not using Vite, you can apply the patch by calling a function directly.

import { DiscordProxy } from '@robojs/patch'

DiscordProxy.patch()

Be sure to call this at the very beginning of your project, before other scripts are loaded. (e.g. the top of your index.js file)

How it works​

This patch works by updating the fetch and WebSocket globals.

Each time a request is made, it makes sure that /.proxy is always included at the beginning of the URL's path. This comforms to the CSP policy set by the Discord Proxy.

This patch is extremely lightweight and only runs when needed. Nothing is patched when running outside of Discord.

External Requests​

This does not affect requests made to external URLs. If you're having CSP issues with those, you may be able to fix them by creating your own Proxy or mapping them in the Discord Developer Portal.

➞ 📚 Tutorial: Resolve CSP Issues with a Proxy

Building Discord Apps?​

Join our Discord Server to chat with other developers, ask questions, and share your projects. We're a friendly bunch and always happy to help! Plus, our very own AI Robo, Sage, is there to assist you with any questions you may have.

➞ 🚀 Community: Join our Discord server

More on GitHub​

Robo.js Logo

MIT © 2024 Robo.js By WavePlay