huntabyte / shadcn-svelte

shadcn/ui, but for Svelte. ✨
https://shadcn-svelte.com
MIT License
4.83k stars 302 forks source link

Consider changing registry servers #423

Closed babakfp closed 6 months ago

babakfp commented 10 months ago

Current Behavior

Hello 👋

I was trying out shadcn-svelte for the first time and I found out there is a problem when downloading components:

npx shadcn-svelte@latest add button
Running the following command will overwrite existing files.
Make sure you have committed your changes before proceeding.

FetchError: request to https://www.shadcn-svelte.com/registry/index.json failed, reason: 
    at ClientRequest.<anonymous> (file:///C:/Users/babak/AppData/Local/npm-cache/_npx/a9116f6e444a1e9e/node_modules/node-fetch/src/index.js:108:11)
    at ClientRequest.emit (node:events:514:28)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
oy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { 
  type: 'system',
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  erroredSysCall: undefined
}

The issue is that the servers are not accessible from my country (Iran). Is it possible to change servers to whatever GitHub uses?


UPDATE:

This issue isn't specific to this library or Vercel.

I don't know what GitHub does to make their servers to be available in Iran. Whatever it is, Vercel can't do it (I talked to them a while ago and they didn't have a solution if I don't misremember).

For almost all of the time that I use the Internet, I use a VPN called v2rayN. In this app, there is an option called "Tun Mode", which if turned on, the whole system uses the new IP and VPN stuff thing. So, this is how I get the VPN working in the console too.

If it's possible to add a note when the connection times out, we can add a link to redirect the users to a page that guides them on how to solve this issue. I can help with writing the guide.

If it is possible to change the servers or have an alternative that kicks in, I'd be happy to help check it out if it works or not.

huntabyte commented 9 months ago

Does having the ability to use a proxy with the CLI not address this issue at all? See: #401 #402

babakfp commented 9 months ago

Does having the ability to use a proxy with the CLI not address this issue at all? See: #401 #402

First time trying it out.

This worked: npx shadcn-svelte@latest add dropdown-menu --proxy zx------join.outline-vpn.cloud:443 This didn't: npx shadcn-svelte@latest init --proxy zx------join.outline-vpn.cloud:443

Does GitHub provide something like Vercel to host it here?

huntabyte commented 9 months ago

We just need to add the proxy option to all the commands and it will work. At this time I'm not considering moving the registry to GitHub or elsewhere.

babakfp commented 9 months ago

Sounds good.

I think adding a note about the proxy option on the installation page can help.

This package svelte-add works fine for me without needing to use a VPN or a proxy option. Maybe it's a good idea to take a look into how they do it later on.

huntabyte commented 9 months ago

If anyone has the cycles to tackle this, we just need to add the proxy options that currently exist for the add command to the init and other commands as well!

babakfp commented 9 months ago

Hey. I can work on it 🤚

sksar commented 8 months ago

We just need to add the proxy option to all the commands and it will work. At this time I'm not considering moving the registry to GitHub or elsewhere.

@huntabyte I believe a better approach can be to use mirrors of the registry servers instead of proxies. If the registry servers don't need any dynamic server-side functionality, then any static web host can serve as a mirror. And the CLI would try these mirrors just in case the primary registry server fails. A good static site hosting will be Cloudflare Pages, since Cloudflare is an edge-only network and has locations in almost every country, with peer-to-peer network with most ISPs of the world.

babakfp commented 8 months ago

Guys, I found a better solution 😄.

I took the JSON registry content, moved it into a fresh SvelteKit project, and deployed it on Netlify. I replaced the registry URL in the CLI with https://inspiring-kheer-efb0f9.netlify.app, tested it out, and things just worked without needing a VPN.

If anyone else wants to test this out, do these steps:

Do this

npx shadcn-svelte-text-abc-cli init

Or do this

  1. Run git clone --depth 1 https://github.com/huntabyte/shadcn-svelte.git.
  2. Open the project in your code editor.
  3. Open this file packages/cli/src/utils/registry/index.ts, and replace const baseUrl = process.env.COMPONENTS_REGISTRY_URL ?? "https://shadcn-svelte.com"; with const baseUrl = "https://inspiring-kheer-efb0f9.netlify.app";.
  4. Run cd packages/cli.
  5. Run pnpm i.
  6. Run pnpm dev (in the first terminal).
  7. In a secondary terminal run pnpm start:dev init.
  8. Done 🎉.

I think this means the whole website needs to be deployed on Netlify.

Maybe react with a 👍 if this works for you.

DevRufai commented 6 months ago

Try switching network.

That resolved it for me

huntabyte commented 6 months ago

We're now running on Cloudflare so this issue should be resolved, if not, it won't be and you'll need to fork and maintain a deployed fork on a server that supports your location.

babakfp commented 6 months ago

It works with no problems 👏👍🌸

shahradelahi commented 3 months ago

Hi,

You can proxy just by adding/exposing HTTP_PROXY to the shell. Please read this Docs: Outgoing Requests. Adding the proxy flag to every command was inconvenient because you could just use an environment variable.

Here are examples of how you can initialize your project with a proxy:

$ HTTP_PROXY=http://localhost:8080 npx shadcn-svelte@latest init
# Or
$ export HTTP_PROXY=http://localhost:8080
$ npx shadcn-svelte@latest init

This is a really late response, I'm sorry.