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

Custom server options for adapter-node #8794

Closed
0324bence opened this issue Jan 30, 2023 · 6 comments
Closed

Custom server options for adapter-node #8794

0324bence opened this issue Jan 30, 2023 · 6 comments

Comments

@0324bence
Copy link

Describe the problem

Currently, when using the node apater you are stuck with one type of server that is automatically created for you when building. This however is not a great solution for many people.
There are hosts that build your application on the server, and you don't have the ability to edit the files in the build directory.

I currently want to implement a socket.io server to start alongside sveltekit, but I haven not found any way to do this currently.

Describe the proposed solution

The best was to do this in my opinion would be to use a process like mankins did in his own adapter.

Alternatives considered

I have tried using the adapter mentioned above, but it only allows 1 file to be transferred, so I couldn't copy the handler.js of the default node apater to make sveltekit actually work.

Importance

would make my life easier

Additional Information

No response

@Conduitry
Copy link
Member

Have you seen https://kit.svelte.dev/docs/adapter-node#custom-server and is this insufficient? What else are you looking for?

If all you want to do is to start another server alongside the default one, you could also just put code to start the server in hooks.server.js. This would also work in dev mode, unlike adapter changes to how the production version of the app is built.

@0324bence
Copy link
Author

0324bence commented Jan 30, 2023

Have you seen https://kit.svelte.dev/docs/adapter-node#custom-server and is this insufficient? What else are you looking for?

Yes, I have seen it, but to my understanding it is instructing me to edit the files in my build folder, which I cannot do. If I missed something please say so. 😄

If all you want to do is to start another server alongside the default one, you could also just put code to start the server in hooks.server.js. This would also work in dev mode, unlike adapter changes to how the production version of the app is built.

How would I go about doing this? Would I start the server on the first request, and do nothing for future requests? Or do I just copy my server code in there, and sveltekit will just run it for me when my app starts?

@Rich-Harris
Copy link
Member

Yes, I have seen it, but to my understanding it is instructing me to edit the files in my build folder, which I cannot do.

The example code is importing from ./build/handler.js — i.e. the file you run (my-server.js, in the example) is in the root of your project. You're not expected to edit the code in the build folder.

How would I go about doing this?

Literally just this:

// src/hooks.server.js
import { start_server } from '$lib/my-stuff.js';
start_server();

That code will run as soon as your SvelteKit server starts.

@0324bence
Copy link
Author

Cool, thank you. I think this is a solution to my problem

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2023
@zxpan
Copy link

zxpan commented Mar 21, 2023

The https://kit.svelte.dev/docs/adapter-node#custom-server is not so clear how to customize node server with express. Could you please share the code how to do customize node server, such as how to compile/build my-server.js, rather than index.js

@samad-kanton
Copy link

samad-kanton commented May 2, 2023

@Rich-Harris being facing challenges on deploying my sveltekit app in my cPanel share hosting with phusionPassenger. Apparently it uses commonjs and if i force it to use es syntax, it shows 500 response error.

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

No branches or pull requests

5 participants