kit
kit copied to clipboard
use `adapter-node` as fallback in `adapter-auto`
Describe the problem
while building locally, the environement is undetectable so i guess no any adapter is used, but i think adpater-node should be used for fallback.
Describe the proposed solution
Add @sveltejs/adapter-node to fallback adapter
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
I'm not sure about this. I'm concerned that, in trying to be helpful, this would actually cause more confusion. The other existing auto adapters are set up to be pretty much just that: automatic. You send the app source off to them, and they build it, and it deploys. There are presumably a number of other steps that are needed when using the Node adapter. You need to worry about the server installing just the prod dependencies. You maybe need to worry about Docker. You need to worry about some sort of reverse SSL proxy in front of the Node server. This all prevents adapter-node from being as automatic as the Cloudflare/Netlify/Vercel ones, and I don't think it should pretend to be.
It might be a little hack-y, but I've been using this to make something similar work in one of my projects
import autoAdapter from "@sveltejs/adapter-auto"
import nodeAdapter from "@sveltejs/adapter-node"
export default {
kit: {
adapter: process.env.IS_VERCEL ? autoAdapter() : nodeAdapter(),
},
...
}
In our case, we want to self-host the app with Node, but also have Vercel serving our PRs without having to do some weird double config re-naming hack in our Dockerfile
It might be a little hack-y, but I've been using this to make something similar work in one of my projects
import autoAdapter from "@sveltejs/adapter-auto" import nodeAdapter from "@sveltejs/adapter-node" export default { kit: { adapter: process.env.IS_VERCEL ? autoAdapter() : nodeAdapter(), }, ... }
In our case, we want to self-host the app with Node, but also have Vercel serving our PRs without having to do some weird double config re-naming hack in our Dockerfile
instead of using hacky way, I guess it would be better to provide an option to use specified adapter as fallback
You maybe need to worry about
if possible, wouldn't it be great if there's an option to use fallback adapter like:
import adapter from "@sveltejs/adapter-auto";
import adapterNode from "@sveltejs/adapter-node";
export default {
kit: {
adapter: adapter({ fallback: "node" })
// or: adapter: adapter({ fallback: adapterNode })
}
}
I agree with adding a fallback to the options that are passed to the adapter.
This isn't hacky, it's a perfectly sensible solution (though I'd change it to adapter-vercel
and just use process.env.VERCEL
since that's set automatically when you're on Vercel):
export default {
kit: {
adapter: process.env.IS_VERCEL ? autoAdapter() : nodeAdapter(),
},
...
}
Defaulting to adapter-node
would be a terrible idea — if the environment isn't recognised, adapter-auto
shouldn't start making wild assumptions about what you want. It should tell you that no supported environment can be detected and point you towards the relevant documentation (which is exactly what happens).