Deploy both preview AND production in one site?

Hey guys! Question for ye:

I’m trying to setup my Nuxt 3 and Storyblok website. In THEIR docs they suggest making a static site for a Preview environment and a static site for a Production environment.

I made 2 sites:

  1. https://nuxt-storyblok-demo-zp.netlify.app
  2. https://nuxt-storyblok-demo-preview.netlify.app

Somehow that name was available lol.

The thing is, those sites are almost exactly the same.

They use the same repo.

The only differences are:

  1. They each have their own webhook
  2. They each have their own environment variables.

My question is:
Do I REALLY need 2 Netlify sites for this? Or is there a way I can just put them to different preview links with different environment variables?

Ideally it’s just one webhook but different environment variables, but some way to manage this in 1 site.

@ZackPlauche I can’t say for certain it would be a suitable fit, but you could investigate:

Branch deploy controls

https://docs.netlify.com/site-deploys/overview/#branch-deploy-controls

Deploy context

https://docs.netlify.com/site-deploys/overview/#deploy-contexts

Hi, I’m pretty sure those deal with multiple git branches. In this case it’s a single branch with different environment variables.

@ZackPlauche They absolutely deal with multiple git branches.

I might be misunderstanding your request, but I interpreted it as wanting both the “preview” and “production” to exist in the one “site”, where I’m interpreting “site” as the site instance within your Netlify account (not literally existing superimposed at the same deployed URL).

My thinking was that you could potentially leverage a branch deploy, of the same code, where the environment variables responsible for outputting ‘preview’ are applied to that branch context.

I’m not sure what you mean by branch specifically :sweat_smile:

I’m a git simpleton who would only ever deploy from Master branch :joy:

Like just 1 github repo → same site settings → site 1 (env vars 1) / site 2 (env vars 2)

@ZackPlauche Yes, I mean an additional branch in the repository.
Not because it needs different code, just to take advantage of the branch deploys and context.

I mean:

1 Github Repo (2 x branches, your main and your ‘preview’ branch)
1 Site in Netlify
Settings mostly shared but with environment variables for each deploy context

See:

But then I would need to somehow update both branches on a git push when I make updates to the code right? :thinking: That seems more complicated.

@ZackPlauche It is more complicated.

But it’s also the only way I’m aware of that could answer your original request/questions:

Do I REALLY need 2 Netlify sites for this?
Or is there a way I can just put them to different preview links with different environment variables?

It’s not really a workflow for your precise situation, usually it’d be used for previewing development branches, or staging where the code has diverged.

You may find it easier to have them configured as separate site instances in Netlify.

It’s also entirely possible Netlify’s staff know of some other way.

Ah ok! Well thanks for taking a look anyways haha.

Having 2 sites is the easier way out here. If you want to complicate things, it could be possible to merge all of it in a single site, but I don’t see the value in that. If you’re really desperate for that, let us know.

For me the easier the better haha.