wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.
https://wasp-lang.dev
MIT License
13.85k stars 1.19k forks source link

Fix netlify.toml that we generate for a web app (client) #2352

Open Martinsos opened 1 month ago

Martinsos commented 1 month ago

This is what our netlify file contains:

[build]
  publish = ".wasp/build/web-app/build/"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200
  force = false

The problem is, this doesn't work for open-saas. Check this discord convo: https://discord.com/channels/686873244791210014/1296434747500920842/1296609588417663086 .

Why doesn't it work for open-saas? Because in open-saas, wasp app is one level deeper from the root of the repo (top level is app/ and blog/). Why is this an issue? Because Netlify resolves that build.publish path against what they call "base dir", and if not specified, they determine "base dir" as a root of the git repo. Which means that when generating netlify.toml, we assumed how far will the .wasp/build/web-app/build/ be positioned from the root of the git repo, while that is an assumption we really shouldn't be making, as it can be anything really.

Reference: https://docs.netlify.com/configure-builds/monorepos/#set-the-base-directory

image

How can we fix this? I have a couple of ideas:

  1. Determine git repo root ourselves and make build.publish be correctly relative to it. Be careful, git repo root might not be the same thing as wasp project root.
  2. Make build.publish be just build/ but then also set "base dir" in netlify.toml to the absolute location of .wasp/build/web-app -> we should be able to do that since we know absolute location of the wasp project. Or we could set "base dir" to wasp project root, and then leave build.publish as it is now. Whatever makes more sense semantically ("base dir" being wasp project vs generated web app).

(2) sounds like a winner to me at the moment.

There is one other interesting think to check though while at this: their docs say:

All paths configured in the netlify.toml should be absolute paths relative to the base directory, which is the root by default (/).

#

Sounds like all these paths should be absolute? But then they should also be relative to base dir? What does that mean, they are absoulte but not in relation to disk, but in relation to base dir? So it should be /.wasp/build/web-app/build/, instead of .wasp/build/web-app/build/? Check their examples of netlify.toml, I think that should clear this up, maybe they just phrased it weirdly.

infomiho commented 1 week ago

Related to #1948 - the same problem occurred but it happened again due to open-saas having the app in the app folder instead of the root folder.