suhaildawood / SvelteKit-integrated-WebSocket

First-class support for WebSockets within SvelteKit by attaching a WebSocket server to the global state.
MIT License
222 stars 13 forks source link

help to deploy on vercel #1

Open robthepaper opened 1 year ago

robthepaper commented 1 year ago

Hi @suhaildawood , thanks for this example of sveltekit + websocket. Works perfectly in development.

But I can't deploy it to vercel, can you give some clues on how we could make this work? I have this error on Vercel build :

Error: No Output Directory named "public" found after the Build completed. You can configure the Output Directory in your Project Settings.

Thanks

lnfel commented 1 year ago

@robotpapier vercel and sveltekit has a comprehensive guide about deployment.

https://vercel.com/docs/frameworks/sveltekit https://kit.svelte.dev/docs/adapter-vercel

Using vercel adapter will build your app in public folder, it seems your svelte.config.js is not set properly.

suhaildawood commented 1 year ago

Glad it was helpful @robotpapier ! This example uses @sveltejs/adapter-node so you'll need a server capable of running the built Node.js script. From what I can tell Vercel does not support WebSocket servers as part of their serverless function offering so I doubt you'll be able to use the Vercel adapter. One option you could look into is Cloudflare - it looks like they do offer support for WebSocket servers within Cloudflare Workers.

If your use case doesn't involve a lot of traffic I'd suggest hosting your site on a small server like the Amazon T2.micro EC2 instance.

robthepaper commented 1 year ago

@suhaildawood yeah indeed I saw that afterwards, thanks for the tips ! :)

aeviou commented 1 year ago

Glad it was helpful @robotpapier ! This example uses @sveltejs/adapter-node so you'll need a server capable of running the built Node.js script. From what I can tell Vercel does not support WebSocket servers as part of their serverless function offering so I doubt you'll be able to use the Vercel adapter.

Could you elaborate on this? I was under the impression that this example app was a server and could be hosted directly on Vercel. I'm not sure I understand how a SvelteKit app can even be a serverless function. I'm not sure if there's some sort of requirement I'm missing..

robthepaper commented 1 year ago

@aeviou Yeah, as @suhaildawood said, and as in the Vercel docs, Vercel doesn't allow websockets connections, so there is no way It can work even if you can deploy it. Luckily for my project, my apps will run locally in production, so I didn't try it on Cloudfare yet with which it should theorically work. Hope it's clearer!

aeviou commented 1 year ago

Ah yes. My misunderstanding was that I didn't understand that Vercel deployed the SvelteKit app as a single serverless function. Thanks for the clarification!