PricingBlog

How to switch between xano data sources.

  • iconic4213-1489968276720189480

    Iconic

    9 days ago

    I would like to know if i can separate my xano datasource in the editor so i can use staging data in the editor and live data in the my deployed app. same for my endpoints with branches, checked the docs and videos no headway. @Andreas Møller any pointers??
  • jaycmpb-1489983276700405780

    Jay Campbell

    9 days ago

    You can have project formula that checks the branch name and it can change the data source based off that.
  • iconic4213-1489992150316748890

    Iconic

    9 days ago

    but even in the editor the branch returns main
  • iconic4213-1491039424962625626

    Iconic

    6 days ago

    @Erik Beuschau any pointers?
  • erikbeus-1491042277399724062

    Erik Beuschau

    6 days ago

    There's currently a bug/limitation with the Branch Name (and a few other) formula when used in the editor. This means that while your branch might be dev or similar, it will always return main within the editor since it's evaluated outside of the canvas/iframe where the editor project itself is running on the main branch.
    We're actively working on a fix for this to make sure that all formula evaluation happens within the iframe to ensure all evaluations are accurate.
    As a temporary fix, you could use a formula like [this](https://editor.nordcraft.com/projects/amethystjangofettworthybear/branches/start/formulas/inIframe?rightpanel=style) that will detect if the formula is evaluated within an iframe or not. You could use that in combination with the Branch Name formula to ensure you always use your staging data if inIframe === true || 'Branch Name' !== 'main'. That should mean you will always use staging data in the editor + on preview branches.
    You can see how this would work [here](https://editor.nordcraft.com/projects/amethystjangofettworthybear/branches/start/components/HomePage?selection=apis.JSON%2520API.url.formula&rightpanel=style) and look at the network requests. It also uses the "staging" url on the [preview url](https://start-amethystjangofettworthybear.nordcraft.site/)
  • iconic4213-1491056771828027412

    Iconic

    6 days ago

    Thanks!
  • But this method would need me to update my endpoints one by one.
  • Is there a way i could update the baseUrl to have this
  • because i have a lot of endoints
  • erikbeus-1491147888645115954

    Erik Beuschau

    6 days ago

    Yes. You can make the base url a global formula which uses this logic to switch between two URLs. Note that custom formulas evaluate to null during SSR (in case that’s necessary)