-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
A way to validate things on server initialization #6147
Comments
You can use https://github.com/sveltejs/kit/tree/master/packages/adapter-node#custom-server for this. |
That's helpful, but what about users who are using other adapters, such as In my example in the OP, I included this text: console.error(
"If you are deploying to Vercel, did you forget to add this environment variable to your project settings page?",
); The idea here is to make it so that this friendly error message would appear in the Vercel "Deployment Status" box, pictured here: In general, I think there is a use-case for providing an adapter-agnostic error message, so that the end-user gets valuable information regardless of the deployment platform that they are using. |
I've argued several times for a "startup" hook that's guaranteed to run right when you start your built app. I think there are many reasons to provide one, this being one of them, but it's also not super straightforward when it should run, especially in environments with the concept of instances, such as serverless platforms. |
The only way to surface runtime errors is by actually running the app, and there's no environment-agnostic way to do that as part of a build step (e.g. in the Vercel case, we'd need to access the deployment, but deployment doesn't happen until after the build step is complete). We could surface startup errors immediately rather than waiting for the first request, just by moving this logic... kit/packages/kit/src/vite/build/build_server.js Lines 109 to 116 in 9a110f5
server.init(...) method (which would become await server.init(...) ): kit/packages/kit/src/vite/build/build_server.js Lines 87 to 102 in 9a110f5
I think we should do that; it would help in the |
I'm with Rich -- simply having |
I created a
but when I run the application using |
Describe the problem
Related to #1538.
In other server solutions, a common pattern is check for the presence of necessary environment variables on startup, for the purposes of showing a friendly error message.
For example:
Doing this kind of thing prevents end-users from having to troubleshoot more-complicated run-time errors. ("Why is the database logic failing? Is the app that I just downloaded bugged?")
In #1538, Rich-Harris recommends using "hooks.js", but this doesn't solve the problem, as the logic in that file will only be executed when a user actually surfs to the page, rather than on server initialization.
Describe the proposed solution
SvelteKit should expose an idiomatic way to perform server-start validation of this manner.
This would also an appropriate place to e.g. initiate necessary database connections, so that the app can e.g. fail early if the database password is wrong (rather than when the first user actually tries to use your product).
Importance
nice to have
The text was updated successfully, but these errors were encountered: