Setting Environment-specific Values in main.wasp File
Currently, in WASP, we're able to insert static og:tags in the main.wasp file's head section like: https://github.com/wasp-lang/open-saas/blob/main/app/main.wasp#L8
However, I'm exploring the possibility of dynamically assigning values to attributes such as og:image and og:url based on the environment.
For instance, in the staging environment, I want to set
og:image
as "https://www.staging.com/public-banner.png", whereas in production, I'd like it to be "https://www.production.com/public-banner.png".
Is there a way to accomplish this dynamic behavior directly within the main.wasp file?Staging.com domain name may be for sale
Staging.com - Contact us for any business inquiries
GitHub
open-saas/app/main.wasp at main · wasp-lang/open-saas
A free, open-source SaaS app starter for React & Node.js with superpowers. Production-ready. Community-driven. - wasp-lang/open-saas
5 Replies
Wohooo @Harish, you just became a Waspeteer level 2!
Hmm. Maybe one of the other guys knows a good solution to this, but I know that we don't have any native Wasp feature that allows for dynamically changing the main.wasp file.
Yeah we don't have that at the moment -> we will likely have it in the future, but that is still very much in the works.
In the meantime, solution might be https://github.com/nfl/react-helmet -> it allows you to set head directly from React. I see it is not currently maintained but allegedly this fork is https://github.com/staylor/react-helmet-async . And to set it in just one place, you can use Wasp's
rootComponent
https://wasp-lang.dev/docs/project/client-config#defining-a-common-layout .
The only difference is that this is then done dynamically through React, instead of Wasp injecting it statically -> I am not sure if that is important for og:image
or not.I opened an issue for it on our Github in the meantime, so we don't forget about it: https://github.com/wasp-lang/wasp/issues/1786 .
GitHub
Make
wasp.main
adjustable based on the external factors (flags?) ...User asked for ability to change some values in main.wasp based on the fact if they are building for staging or for production, specifically they wanted to change the text in head, for og:image tag...
Thanks @Vinny (@Wasp) and @martinsos. Will try the workaround and let you guys know how it goes.