Skip to main content

Overview

Open Higgsfield AI is a fully client-side application built with Vite, making it simple to deploy to any static hosting provider. This guide covers production builds, deployment options, and security best practices.

Prerequisites

1

Node.js and npm

Ensure you have Node.js 18+ installed:
node --version  # Should be 18.0.0 or higher
npm --version
2

Clone the Repository

git clone https://github.com/yourusername/open-higgsfield-ai.git
cd open-higgsfield-ai
3

Install Dependencies

npm install
This installs:
  • vite - Build tool and dev server
  • tailwindcss - CSS framework
  • puppeteer - For any server-side rendering needs (optional)

Building for Production

Standard Build

npm run build
The dist/ folder contains your optimized production build.
Build Details:
  • JavaScript is minified and tree-shaken
  • CSS is optimized with Tailwind’s purge
  • Assets are fingerprinted with content hashes
  • Total bundle size: ~500KB (depending on assets)

Build Configuration

Vite configuration from vite.config.js:
import { defineConfig } from 'vite';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
    plugins: [
        tailwindcss(),
    ],
    server: {
        proxy: {
            '/api': {
                target: 'https://api.muapi.ai',
                changeOrigin: true,
                secure: false
            }
        }
    }
});
The proxy configuration only applies to development (npm run dev). In production, the app makes direct requests to api.muapi.ai.

Serving the Built App

Local Preview

Test your production build locally:
npm run preview
This serves the dist/ folder on http://localhost:4173.

Static Hosting Providers

One-Click Deploy
npm install -g vercel
vercel
Build Configuration:
{
  "buildCommand": "npm run build",
  "outputDirectory": "dist",
  "framework": "vite"
}
Custom Domain:
  • Go to Vercel project settings
  • Add your domain
  • Update DNS CNAME to cname.vercel-dns.com

Environment Considerations

API Proxy (Development vs Production)

// From muapi.js:6
this.baseUrl = '';  // Uses Vite proxy at http://localhost:5173/api
The client automatically detects the environment:
this.baseUrl = import.meta.env.DEV ? '' : 'https://api.muapi.ai';
In production, your app makes direct requests to api.muapi.ai. CORS is already configured by Muapi.ai, so no additional proxy is needed.

Browser Compatibility

Open Higgsfield AI supports modern browsers:
  • Chrome 90+
  • Firefox 88+
  • Safari 14+
  • Edge 90+
ES2020+ features used:
  • Optional chaining (?.)
  • Nullish coalescing (??)
  • async/await
  • ES Modules
For older browser support, add browserslist and Babel to your build pipeline.

CORS and API Access

Why CORS Works in Production

Muapi.ai’s API includes these CORS headers:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type, x-api-key
This allows direct browser-to-API communication without a proxy.

Development Proxy Explanation

During development, Vite’s proxy (configured in vite.config.js) avoids browser CORS restrictions:
server: {
    proxy: {
        '/api': {
            target: 'https://api.muapi.ai',
            changeOrigin: true,  // Changes host header
            secure: false        // Allows self-signed certs
        }
    }
}
Request Flow:
Browser → http://localhost:5173/api/v1/flux-dev-image
         ↓ (Vite proxy)
         → https://api.muapi.ai/api/v1/flux-dev-image

Security Best Practices

Critical Security Rules:
  1. Never commit API keys to your repository
  2. Use HTTPS for all production deployments
  3. Enable security headers (see Docker nginx example)
  4. Validate user inputs before sending to API
  5. Monitor API usage to detect abuse

Secure API Key Management

Option 1: User-Provided Keys (Recommended) Users enter their own Muapi.ai API key in Settings:
// Stored in browser localStorage
localStorage.setItem('muapi_key', userProvidedKey);
Option 2: Environment Variables (For Private Deployments) If hosting privately for your team:
# .env.local
VITE_MUAPI_KEY=your-api-key
// muapi.js
getKey() {
    return import.meta.env.VITE_MUAPI_KEY || localStorage.getItem('muapi_key');
}
Never use environment variables in public deployments—the key will be visible in the bundled JavaScript!

Content Security Policy (CSP)

Add CSP headers to prevent XSS attacks:
Content-Security-Policy: default-src 'self'; 
  script-src 'self' 'unsafe-inline'; 
  style-src 'self' 'unsafe-inline'; 
  img-src 'self' data: https:; 
  connect-src 'self' https://api.muapi.ai;

Rate Limiting

Implement client-side rate limiting to prevent abuse:
class RateLimiter {
    constructor(maxRequests = 10, windowMs = 60000) {
        this.requests = [];
        this.maxRequests = maxRequests;
        this.windowMs = windowMs;
    }

    canMakeRequest() {
        const now = Date.now();
        this.requests = this.requests.filter(t => now - t < this.windowMs);
        
        if (this.requests.length >= this.maxRequests) {
            return false;
        }
        
        this.requests.push(now);
        return true;
    }
}

const limiter = new RateLimiter(10, 60000); // 10 requests per minute

Performance Optimization

Asset Optimization

# Optimize cinema control assets
for file in public/assets/cinema/*.{png,jpg}; do
  cwebp -q 80 "$file" -o "${file%.*}.webp"
done

Caching Strategy

Static Assets:
location ~* \.(js|css|png|jpg|jpeg|gif|webp|svg|ico)$ {
    expires 1y;
    add_header Cache-Control "public, immutable";
}
API Responses: Cache completed generation results locally:
const cacheResult = (requestId, result) => {
    const cache = JSON.parse(localStorage.getItem('result_cache') || '{}');
    cache[requestId] = { result, timestamp: Date.now() };
    localStorage.setItem('result_cache', JSON.stringify(cache));
};

Monitoring and Analytics

Error Tracking

Integrate Sentry for error monitoring:
npm install @sentry/browser
import * as Sentry from "@sentry/browser";

Sentry.init({
  dsn: "your-sentry-dsn",
  environment: import.meta.env.MODE,
  tracesSampleRate: 0.1,
});

Usage Analytics

Track model usage with Google Analytics or Plausible:
// After successful generation
window.gtag?.('event', 'generation_complete', {
  model_id: params.model,
  studio_type: 'image',  // or 'video', 'cinema'
});

Health Checks and Uptime

API Health Endpoint

Add a simple health check:
// src/health.js
export async function checkAPIHealth() {
    try {
        const response = await fetch('https://api.muapi.ai/health');
        return response.ok;
    } catch {
        return false;
    }
}

Uptime Monitoring

Use services like:
  • UptimeRobot - Free tier available
  • Pingdom - Detailed performance metrics
  • Checkly - API monitoring with Playwright

Troubleshooting Production Issues

Cause: Incorrect base URL or missing index.html fallback.Solution:
  • Check vite.config.js base URL matches deployment path
  • Ensure server redirects all routes to /index.html
  • Verify dist/index.html exists
Cause: Base path mismatch or incorrect nginx/hosting config.Solution:
  • Check browser DevTools Network tab for failed requests
  • Verify base in vite.config.js
  • Ensure assets are copied to dist/assets/
Cause: Incorrect production API URL or network issue.Solution:
  • Verify muapi.js:6 uses https://api.muapi.ai in production
  • Check API key is valid
  • Test API directly with curl:
    curl -H "x-api-key: YOUR_KEY" https://api.muapi.ai/health
    
Cause: Incognito mode or browser settings blocking storage.Solution:
  • Test in normal browser window
  • Check browser storage permissions
  • Add fallback to sessionStorage if needed

Next Steps

API Configuration

Set up your Muapi.ai API key

Model Selection

Choose the right models for your deployment

Build docs developers (and LLMs) love