Skip to content

isProduction() – Environment Checker for Merciglobal Cloud ERP

Overview

The isProduction() function is a custom JavaScript utility provided by Merciglobal Cloud ERP to determine whether the current running environment is the production (customer) server or a development (internal) server.

This helps in conditionally executing environment-specific code such as: - Enabling debug logs only in development - Disabling test workflows in production - Switching between sandbox and live APIs


Function Definition

function isProduction() {
    // Logic implemented to check the environment
    return (window.location.hostname !== 'localhost' &&
            !window.location.hostname.includes('dev') &&
            !window.location.hostname.includes('staging'));
}

How it Works

The function checks the window.location.hostname against common non-production indicators such as:

  • 'localhost' → Local development
  • Hostnames that include 'dev' or 'staging'

If none of the above are detected, it assumes it's running on a live production server.


Usage Example

if (isProduction()) {
    console.log('Running in production environment');
    // Load live APIs
} else {
    console.log('Running in development or staging environment');
    // Load sandbox APIs or enable debug logs
}

Use Cases in Merciglobal Cloud ERP

  • Sales Modules: Enable live CRM APIs only when isProduction() returns true.
  • Inventory & Warehouse: Avoid triggering actual stock movements during testing.
  • Finance/Accounting: Use sandbox payment gateways during development.

Best Practices

  • Always wrap critical production logic inside an isProduction() check.
  • Avoid hard-coding environment-specific URLs without checking the environment.
  • Keep the hostname check logic updated if new dev/staging subdomains are introduced.

Internal Notes for Merci Developers

  • You can override the default behavior by mocking window.location.hostname in unit tests.
  • Consider extending the logic to include .env-based configurations in future versions.

Common Questions

Q: Can I use this in mobile or embedded views?

This function depends on the browser's window.location. Ensure it's executed in a browser context.

Q: What if our dev server uses a custom domain like test.merci.com?

You can update the function to include more flexible hostname patterns.

function isProduction() {
    const nonProdPatterns = ['localhost', 'dev', 'staging', 'test'];
    return !nonProdPatterns.some(pattern => window.location.hostname.includes(pattern));
}

  • .env configuration management
  • Logging & Debugging in Merciglobal
  • API mode switching (sandbox vs live)

For more utilities and functions, check out the internal Merci Developer Docs Portal.

Keep production safe. Always verify with isProduction() 😉