Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document how to debug CORS issues #256

Open
nick1udwig opened this issue Oct 23, 2024 · 2 comments
Open

document how to debug CORS issues #256

nick1udwig opened this issue Oct 23, 2024 · 2 comments
Assignees

Comments

@nick1udwig
Copy link
Contributor

https://discord.com/channels/1186394868336038080/1186421052071477428/1298665751653253241

@barraguda
Copy link
Contributor

In this case it was the dev trying to hit their kinode directly with fetch(/localhost:8080/process:pkg:publisher/some-path and running into cors issues because that browser tab was running on localhost:5137.

The solution is to just hit fetch(/process:pkg:publisher/some-path), and then define a proxy in your vite config like this:

// This is the proxy URL, it must match the node you are developing against
const PROXY_URL = (process.env.VITE_NODE_URL || 'http://127.0.0.1:8080').replace('localhost', '127.0.0.1');

export default defineConfig({
  base: BASE_URL,
  server: {
    proxy: {
      [`^${BASE_URL}/our.js`]: {
        target: PROXY_URL,
        changeOrigin: true,
        rewrite: (path) => {
          console.log('Proxying  jsrequest:', path);
          return '/our.js';
        },
      },
      [`^${BASE_URL}/kinode.css`]: {
        target: PROXY_URL,
        changeOrigin: true,
        rewrite: (path) => {
          console.log('Proxying  csrequest:', path);
          return '/kinode.css';
        },
      },
      // This route will match all other HTTP requests to the backend
      [`^${BASE_URL}/(?!(@vite/client|src/.*|node_modules/.*|@react-refresh|$))`]: {
        target: PROXY_URL,
        changeOrigin: true,
      },

    },
  },
});

@barraguda
Copy link
Contributor

We have some frontend tutorials in our book, but most of them omit the actual UI dev process, I'll see if I can add some basic into the chess or chat cookbook, so we can map out some of these basic pitfalls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants