Watch a live product demo 👀 See how Sanity powers richer commerce experiences

How to Avoid Exposing the Backend on Netlify

4 replies
Last updated: Jun 23, 2021
If the studio directory is a sibling to your front end, you can specify the base directory in Netlify settings. If the studio directory is a child (i.e., it’s contained inside your front end directory), I imagine you could add it to .gitignore but you’d need to make sure the scripts in your package.json aren’t looking for it. My suggestion would be to see what the
build
script is running in package.json. You can either add a script that only builds your front end and then tell Netlify to run that, or you could edit the build script.
Jun 22, 2021, 4:04 AM
user Y

I see. So, you the Front End or the "client" is a child directory inside the studio directory.

Your Build process is picking up the outermost
package.json
which in this case is Studio's
package.json
and not your Front End's.
In order to ensure that the hosting provider (Netlify) in this case starts the correct build process, you need to specify the project's root, as suggested above by
user A
.
Here is a link on how to do so:
https://docs.netlify.com/configure-builds/get-started/#basic-build-settings
(Check the Base directory option).

Also, may I please request the structure of the
client
. (I want to confirm whether or not they have separate
package.json
or not.) If not then, it is possible that all the libraries required by your "client" may have been listed as a dependency in the root
package.json
(The one that is actually meant for the Studio).
By the way, for better separation, I believe you should extract the client and the studio to a common parent (following a
monorepo
pattern) or separate repositories entirely and you should do this as soon as possible.
Jun 22, 2021, 10:46 AM
user Y

I see. So, you the Front End or the "client" is a child directory inside the studio directory.

Your Build process is picking up the outermost
package.json
which in this case is Studio's
package.json
and not your Front End's.
In order to ensure that the hosting provider (Netlify) in this case starts the correct build process, you need to specify the project's root, as suggested above by
user A
.
Here is a link on how to do so:
https://docs.netlify.com/configure-builds/get-started/#basic-build-settings
(Check the Base directory option).

Also, may I please request the structure of the
client
. (I want to confirm whether or not they have separate
package.json
or not.) If not then, it is possible that all the libraries required by your "client" may have been listed as a dependency in the root
package.json
(The one that is actually meant for the Studio).
By the way, for better separation, I believe you should extract the client and the studio to a common parent (following a
monorepo
pattern) or separate repositories entirely and you should do this as soon as possible.
Jun 22, 2021, 10:46 AM
I see.
Well, yeah, so incorrect build process is being started.

You may now change the project's root using Netlify's settings.
Jun 22, 2021, 2:41 PM
I could be wrong, but if Netlify’s NODE_ENV is set to production, devDependencies will not be installed. The build log is referring to tailwindcss but it’s a devDependency in your package.json. I wonder if you were to set it as a dependency if this would work.
Jun 23, 2021, 3:10 AM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing