-
-
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
Ability to run code on server start #208
Comments
Depends on the specifics. We already have this... // src/setup/index.js
export function prepare(headers) {
// this function runs before every page/endpoint request
return {
context: {...}, // this object is passed to endpoints, and used to derive session
headers: {...} // this object is mixed in with response headers
};
}
export function getSession(context) {
return {
user: context.user && {
name: user.name
}
};
} ...but without knowing more about the problem it's hard to know if that's the solution |
I followed up with the user. It seems they were conflating a couple different issues. Their main complaint was around Snowpack's bundling of Node dependencies. I've opened a new issue for that (#210) But anyway, it does seem like it'd be a nice API to support one-time setup stuff somewhere. You can probably work around it using the per-request method and setting a global flag to have it executed only on the first call, but it's a little messy to do it that way and if it takes a long time you might have requests that are hanging or failing whereas if it were done separately it might be able to be better handled |
Still not totally sure what the suggestion is — what does 'one-time setup' mean in the context of a serverless deployment (for example)? |
Yeah, I guess it wouldn't mean much in that context, which is an interesting call out. I'll close this for now and let that thought bounce around in my head for awhile |
@aewing on Discord couldn't figure out how to do database setup. Was requesting:
I ignore most of the help requests, but this one seemed like it might be a feature gap rather than a usage / documentation issue. Feel free to close if this use case is already supported in some way
The text was updated successfully, but these errors were encountered: