Difficult Migrating API in Mongorepo Project
I have a project that is structured in a monorepo. And we’re migrating our API from a standalone express API to a serverless function model.
But we’d really love to keep our overall structure. As it makes it easier to abstract and separate the different architectural pieces. But to my understanding right now Netlify combines the base directory for your static assets (the UI) and the serverless functions
Ideally, I’d like this structure:
clientFolder/
serverlessFolder/
netlify.toml
How can I achieve this structure?
I’ve tried using subshells and similar approaches of CDing into a subdirectory and then executing a command but I end up getting a ‘gatsby not found’ error when building
Example Error Message
Config Causing Error Message
For the build command, I’ve tried both “cd client && npm run build” and "(cd client && npm run build)
[build]
base = ""
publish = "client/public/"
command = "cd client && npm run build"
[[headers]]
for = "*.js" # js files should be set this way
[headers.values]
Cache-Control = "public, max-age=604800"
[[headers]]
for = "*.css" # css files too
[headers.values]
Cache-Control = "public, max-age=604800"
[[plugins]]
package = "@netlify/plugin-lighthouse"
# optional, fails build when a category is below a threshold
[plugins.inputs.thresholds]
accessibility = 0.9
best-practices = 0.9
performance = 0.1
pwa = 0.5
seo = 0.9
[[plugins]]
package = "netlify-plugin-gatsby-cache"
[[plugins]]
package = "netlify-plugin-inline-critical-css"
Current Configuration That Does Work
[build]
base = "client/"
publish = "public/"
command = "npm run build"
[[headers]]
for = "*.js" # js files should be set this way
[headers.values]
Cache-Control = "public, max-age=604800"
[[headers]]
for = "*.css" # css files too
[headers.values]
Cache-Control = "public, max-age=604800"
[[plugins]]
package = "@netlify/plugin-lighthouse"
# optional, fails build when a category is below a threshold
[plugins.inputs.thresholds]
accessibility = 0.9
best-practices = 0.9
performance = 0.1
pwa = 0.5
seo = 0.9
[[plugins]]
package = "netlify-plugin-gatsby-cache"
[[plugins]]
package = "netlify-plugin-inline-critical-css"
Edit 2
If you try to configure a functions directory that is outside of the base directory it won’t work. It will tell you:
Configuration property build.functions must be inside the root directory.
Invalid syntax
[build]
functions = “…/serverless/”Valid syntax
[build]
functions = “serverless/”