@robojs/patch
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Generated with create-robo magic!


@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 Entry Point Command

If your Discord Activity is old or you're using the same Discord App for bots and activities, you may encounter issues with the entry point command missing as well as your activity's launch button.

This patch fixes those issues by adding the missing command to your Discord App when it goes missing. Automatically. Just by having this patch installed. 🎩✨

Please be sure to have both DISCORD_CLIENT_ID and DISCORD_TOKEN environment variables set in your .env file.

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.

Method 1: Vite Plugin (Recommended)

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

Package Sidebar

Install

npm i @robojs/patch

Weekly Downloads

20

Version

0.2.0

License

MIT

Unpacked Size

26.3 kB

Total Files

36

Last publish

Collaborators

  • pkmmte