kit icon indicating copy to clipboard operation
kit copied to clipboard

use `adapter-node` as fallback in `adapter-auto`

Open sharmapukar217 opened this issue 2 years ago • 4 comments

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

sharmapukar217 avatar Dec 16 '22 14:12 sharmapukar217

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.

Conduitry avatar Dec 18 '22 04:12 Conduitry

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

AndreasPB avatar Dec 22 '22 14:12 AndreasPB

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

sharmapukar217 avatar Dec 25 '22 16:12 sharmapukar217

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 })
   }
}

sharmapukar217 avatar Dec 25 '22 17:12 sharmapukar217

I agree with adding a fallback to the options that are passed to the adapter.

HikaruHokkyokusei avatar Dec 30 '22 13:12 HikaruHokkyokusei

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).

Rich-Harris avatar Jan 28 '23 01:01 Rich-Harris