Back to Articles
Server & Deployment Oct 31, 2026 6 min read

How to Connect an HTTPS Frontend to an HTTP Backend on Vercel Without Mixed Content Errors

Deployed your Angular SPA to Vercel only to get 404s and Mixed Content blocks against your HTTP backend? Here is how to fix Angular’s nested output directory and build a zero-overhead streaming reverse proxy in Vercel to route your API securely.

How to Connect an HTTPS Frontend to an HTTP Backend on Vercel Without Mixed Content Errors

When deploying a full-stack project where the frontend is hosted on Vercel and the backend is on a platform without an active SSL certificate (such as MonsterASP / RunASP.NET), you will inevitably run into two major deployment roadblocks:

  1. Angular 17+ Application Builder 404s on Vercel (Nested /browser directory & SPA route refreshes).
  2. Browser Mixed Active Content Blocking (An HTTPS frontend attempting to make HTTP API requests).

Here is a step-by-step breakdown of why these errors happen and how we solved both cleanly using a zero-overhead Vercel Serverless Reverse Proxy.


The Architectural Setup

  • Frontend: Angular 22 Single Page Application (SPA) deployed to Vercel (https://your-site.vercel.app).
  • Backend: ASP.NET Core Web API hosted on MonsterASP over plain HTTP (http://your-site.runasp.net).

Problem 1: Angular Build Output & SPA 404 on Vercel

The Symptom

After deploying the Angular project to Vercel, navigating to the website resulted in:

GET https://your-app.vercel.app/ 404 (Not Found)

The Root Cause

  1. The Nested Output Folder: Modern Angular (v17+ with @angular/build:application) automatically outputs compiled static files into a nested subfolder: dist/<project-name>/browser/. However, Vercel’s Angular preset looks for index.html at the root of dist/<project-name>/. Because index.html was inside .../browser/index.html, Vercel could not find it.

  2. Single Page Application (SPA) Routing: Angular uses client-side HTML5 routing (PathLocationStrategy). Whenever a user refreshes the page on /company-login or /dashboard, Vercel searches for a physical static file named company-login.html, which doesn't exist.

The Fix

1. Flatten the Output Directory in angular.json

Configure "outputPath" with "browser": "" so Angular places all build assets and index.html directly in dist/<project-name>:

"architect": {
  "build": {
    "builder": "@angular/build:application",
    "options": {
      "browser": "src/main.ts",
      "outputPath": {
        "base": "dist/erp-dashboard",
        "browser": ""
      },
      "tsConfig": "tsconfig.app.json"
    }
  }
}

2. Configure SPA Route Rewrites in vercel.json

Instruct Vercel to route any non-static client URL back to /index.html:

{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "outputDirectory": "dist/erp-dashboard",
  "rewrites": [
    {
      "source": "/(.*)",
      "destination": "/index.html"
    }
  ]
}

Problem 2: The Browser "Mixed Content" Block

The Symptom

Once the homepage loaded, submitting the login form failed with this console error:

Mixed Content: The page at 'https://your-site.vercel.app/company-login' was loaded over HTTPS, 
but requested an insecure resource 'http://your-site.runasp.net/api/v1/auth/login'. 
This request has been blocked; the content must be served over HTTPS.

The Root Cause

All modern web browsers (Chrome, Edge, Firefox, Safari) enforce Mixed Active Content Blocking as part of W3C security standards:

  • An HTTPS page is strictly prohibited from making active network requests (fetch or XMLHttpRequest) to an unencrypted HTTP endpoint.
  • The browser drops the request instantly inside the browser before it ever leaves your computer.

Because free hosting plans often do not include free SSL for subdomains, the backend could only serve traffic over http://.


Problem 3: Vercel Catch-All Routing in Standalone Projects

When attempting to create a serverless proxy at api/[...path].js:

api/v1/auth/login: 404 (Not Found)

The Root Cause

The bracketed [...path].js wildcard naming convention is a Next.js-only framework feature. In standalone or non-Next.js projects (like an Angular SPA on Vercel), Vercel does not parse brackets as dynamic routes; it literally looks for a file named [...path].js.

In standalone Vercel deployments, the standard pattern is:

  1. A single entrypoint file: api/index.js.
  2. An explicit wildcard rewrite rule in vercel.json: /api/:path* -> /api/index.js.

The Complete Solution: High-Performance Vercel Reverse Proxy

To bypass the browser's Mixed Content security restriction without needing an SSL certificate on the backend host, we proxy API traffic through Vercel's edge network:

Browser (HTTPS)
   │
   │  POST https://your-site.vercel.app/api/v1/auth/login
   ▼
Vercel Edge Function (HTTPS)  <-- Same Origin! No Mixed Content! No CORS!
   │
   │  Streams request server-to-server over HTTP port 80
   ▼
Backend Server (http://your-site.runasp.net/api/v1/auth/login)

Because the browser only speaks HTTPS to Vercel on the same origin:

  • 0 Mixed Content Errors: The browser's communication is 100% HTTPS.
  • 0 CORS Preflight Latency: Because the request is same-origin, browsers skip unnecessary OPTIONS preflight requests.
  • Full Feature Support: Cookies, JSON payloads, and multipart/form-data file uploads stream seamlessly.

Step 1: Update Angular Environment to Relative URLs

In src/environments/environment.ts:

export const environment = {
  production: true,
  apiBaseUrl: '/api/v1', // Relative URL — routed to same origin
} as const;

In src/environments/environment.development.ts:

export const environment = {
  production: false,
  apiBaseUrl: 'http://localhost:5259/api/v1', // Direct to local API
} as const;

Step 2: Create the Streaming Proxy in api/index.js

Create api/index.js at the root of your Angular project:

const http = require('http');

module.exports = function handler(req, res) {
  let targetPath = req.url || '/api';

  // Handle cases where the rewrite passes through /api/index.js
  if (targetPath.startsWith('/api/index.js')) {
    const queryPath =
      req.query && req.query.path
        ? Array.isArray(req.query.path)
          ? req.query.path.join('/')
          : req.query.path
        : null;
    if (queryPath) {
      const qIndex = targetPath.indexOf('?');
      const search = qIndex !== -1 ? targetPath.slice(qIndex) : '';
      targetPath = `/api/${queryPath}${search}`;
    }
  }

  // Ensure path starts with /api
  if (!targetPath.startsWith('/api')) {
    targetPath = `/api${targetPath.startsWith('/') ? '' : '/'}${targetPath}`;
  }

  // Forward incoming headers and override Host for IIS virtual hosting
  const headers = { ...req.headers };
  headers.host = 'erpbd.runasp.net'; // Crucial for IIS binding
  delete headers['x-vercel-id'];
  delete headers['x-vercel-deployment-url'];
  delete headers['x-forwarded-host'];

  // Open HTTP connection to the backend
  const proxyReq = http.request(
    {
      hostname: 'erpbd.runasp.net',
      port: 80,
      path: targetPath,
      method: req.method,
      headers: headers,
    },
    (proxyRes) => {
      // Pipe response status and headers back to browser
      res.writeHead(proxyRes.statusCode, proxyRes.headers);
      proxyRes.pipe(res);
    }
  );

  proxyReq.on('error', (err) => {
    if (!res.headersSent) {
      res.writeHead(502, { 'Content-Type': 'application/json' });
      res.end(
        JSON.stringify({
          isSuccess: false,
          message: 'Gateway Proxy Error: ' + err.message,
        })
      );
    }
  });

  // Stream request body (JSON, FormData, etc.) directly without memory buffering
  req.pipe(proxyReq);
};

// Disable Vercel's body parser to allow raw stream piping (handles file uploads)
module.exports.config = {
  api: {
    bodyParser: false,
  },
};

Why bodyParser: false and req.pipe(proxyReq)?

By turning off Vercel's default body parser:

  1. Node.js treats incoming requests as raw data streams.
  2. Large payloads and file uploads (multipart/form-data) are piped directly to the backend without consuming memory or encountering parsing bottlenecks.

Step 3: Configure vercel.json with Negative Lookahead Rewrites

In vercel.json:

{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "outputDirectory": "dist/erp-dashboard",
  "rewrites": [
    {
      "source": "/api/:path*",
      "destination": "/api/index.js"
    },
    {
      "source": "/((?!api/).*)",
      "destination": "/index.html"
    }
  ]
}
  • Rule 1 (/api/:path*): Routes all API requests directly into the api/index.js serverless function.
  • Rule 2 (/((?!api/).*)): Uses regex negative lookahead to route any non-API route to /index.html for Angular's client-side router.

Summary of Results

ProblemRoot CauseSolution
GET / 404 (Not Found)Angular 17+ outputs to dist/.../browser/ by default.Flatten output path with "outputPath": { "base": "dist/...", "browser": "" }.
Mixed Content ErrorHTTPS frontend blocked from calling HTTP backend.Proxy /api/* via Vercel Serverless Function over same-origin HTTPS.
/api/... 404 Not Found[...path].js is Next.js-only syntax.Use api/index.js with an explicit /api/:path* rewrite in vercel.json.
Route Refresh 404sAngular SPA client routing.Exclude /api using negative lookahead (/((?!api/).*)) rewriting to /index.html.

Share this article

Dabananda Mitra

Dabananda Mitra

Software Engineer specializing in scalable backend systems and minimal, effective API design.

Comments

Loading comments...