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.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in