Origin variables / staging vs production

Hi, I have basically the same question as this closed topic: Production vs. Development - #5 by EyalGershon

We’re trying to deploy an app to a staging origin and a production origin. But is there a way to set variables in the origin context?
In the topic linked above it is suggested to use two Connections with hard coded baseURLs. This works, but would require us to duplicate the code/config for the connections AND the webhooks that refer to a connection (since this is configured on the “components”-level in makecomapp.json).

If some variable/label/anything could be picked up from origin config when setting the baseURL in Base/Connection it would be much more convenient.

Suggestions?

hmm what about using a condition based on the environment ?
My condition was according to a parameter but you can base your condition according to the connection environment variable.
Look at this example if it makes sense to you:

[
	{
		"condition": "{{length(parameters.orderby.sortedField) > 0}}",
		"url": "/{{parameters.entity}}",
		"method": "GET",
		"qs": {
			"$filter": "{{parameters.filter}}",
			"$since": "{{parameters.since}}",
			"$orderby": "{{parameters.orderby.sortedField}}{{parameters.orderby.order}}",
			"$skip": "{{parameters.skip}}",
			"$select": "{{parameters.select}}",
			"$top": "{{parameters.limit}}",
			"$expand": "{{parameters.expand}}"  
		},                      
		"response": {
			"iterate": "{{body.value}}",
			"output": "{{item}}"
		}
	},
	{
		"condition": "{{length(parameters.orderby.sortedField) = 0}}",
		"url": "/{{parameters.entity}}",
		"method": "GET",
		"qs": {
			"$filter": "{{parameters.filter}}",
			"$since": "{{parameters.since}}",
			"$skip": "{{parameters.skip}}",
			"$select": "{{parameters.select}}",
			"$top": "{{parameters.limit}}",
			"$expand": "{{parameters.expand}}"  
		},                      
		"response": {
			"iterate": "{{body.value}}",
			"output": "{{item}}"
		}
	}
]

Sorry, but no, I can’t make sense of your example :sweat_smile:

How/where do I set a connection environment variable?

We kind of solved like this now:
makecomapp.json:

...
"components": {
        "connection": {
            "connection-prod": {
                "label": "My Production",
                "connectionType": "basic",
                "codeFiles": {
                    "communication": "connections/connection-prod/connection-prod.communication.iml.json",
                    "params": "connections/connection-prod/connection-prod.params.iml.json",
                    "common": null
                }
            },
            "connection-stage": {
                "label": "My Stage",
                "connectionType": "basic",
                "codeFiles": {
                    "communication": "connections/connection-stage/connection-stage.communication.iml.json",
                    "params": "connections/connection-stage/connection-stage.params.iml.json",
                    "common": null
                }
            }
        },
...
    "webhook": {
            "webhook1": {
                "label": "Get data webhook",
                "webhookType": "web",
                "connection": "connection-stage",
...
"origins": [
        {
            "label": "Stage",
            "baseUrl": "https://eu2.make.com/api",
            "appId": "some-id-123",
            "appVersion": 1,
            "apikeyFile": "../.secrets/apikey",
            "idMapping": {
                "connection": [
                    {
                        "local": "connection-stage",
                        "remote": "some-id-123"
                    },
                    {
                        "local": "connection-prod",
                        "remote": null
                    }
                ],
...
{
            "label": "Production",
            "baseUrl": "https://eu2.make.com/api",
            "appId": "some-id-777",
            "appVersion": 1,
            "idMapping": {
                "connection": [
                    {
                        "local": "connection-prod",
                        "remote": "some-id-777"
                    },
                    {
                        "local": "connection-stage",
                        "remote": null
                    }
                ],

The fact that webhook1 refers to connection-stage doesn’t seem to matter. It ends up referring to the connection “enabled” in the origin.
We still have to duplicate the connection for this to work - each having a hidden parameter with a default value (but I guess a “common” variable on each would’ve worked too). But at least the duplication stops there.
I still would’ve preferred to see the possibility of defining some variable directly on the origin and just use that but at least we have a working development/deploy flow now.

Hi @Wiccy ,

Why don’t you work with a select parameter as one of your connections parameter? The label can be “Production” or “Staging”, the value however can be the right base url. Then point to this parameter in your base as your baseUrl. I assume all other parameters remain the same.

If not, you can also use “prod” and “stage” (or something similar) as values of the select parameter and use this in your conditions to select the right URL and parameters.

Glenn - Callinetic

Wouldn’t that mean the users of the published app could choose between stage/prod?

Interesting thoughts.
I was thinking of leveraging git features on my side. Having a main and dev branches with different configurations and merging dev to main whenever I want to release a prod version.
This way you don’t have to duplicate connection, base or universal module.

Where would you store the URLs for dev/prod in order for them to not overwrite each other on merge?

I was thinking of using git hooks.

But, I think I found a much simpler way…

I created a common variable (in base and connection)

{
  "server":"https://myserver.com"
}

and replace the server with {{common.server}} wherever needed.
Then I just need to make sure I don’t crush the common variable (but they don’t even seems to be synchronized with VS Code as it’s supposed to be user for secrets)