Help related to webhook url

So basically, I am developing a SaaS, however I am stuck on a part where the webhook URL is currently hard-coded into the app. So there is 2 choices of putting the webhook URL to avoid that - Env variable, or proxy server. I do not have enough knowledge about the proxy server option, so I am more looking forward to the Env variable. The only confusion is if I later develop a mobile application of the app, how can the users view the webhook URL on files. What shall I do?

1 Like

Hi @curatorcvn Welcome!
I have done that , just set your WEBHOOK_URL environment variable to your public facing URL, so that whenever n8n generates a webhook or form url it will use that.

See this:

Hey welcome! So the env variable approach is solid for your backend, but for a mobile app you cant really read env vars directly since those are server-side only. What i would do is have your backend serve the webhook URL through a simple API endpoint like /api/config and then your mobile app just fetches it from there on startup. That way you only change it in one place.

Environment Variables (Backend)

// Instead of hardcoding:
const WEBHOOK_URL = process.env.N8N_WEBHOOK_URL;

// Different environments:
// Dev: http://localhost:5678/webhook/123
// Prod: https://n8n.yoursaas.com/webhook/123

For n8n itself, set in docker-compose:

environment:
  - WEBHOOK_URL=https://n8n.yoursaas.com/
  - N8N_HOST=n8n.yoursaas.com

Config Endpoint (For Mobile Apps)

Create a simple API endpoint that mobile apps call on startup:

app.get('/api/app-config', (req, res) => {
  res.json({
    webhookUrl: process.env.N8N_WEBHOOK_URL,
    apiVersion: '1.0'
  });
});

Main advantage: Webhook URL can be updated at any point in time through a backend env var – no app update needed!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.