Proxy

Provides an HTTP proxy while still enforcing your app's security

Technology

The proxy module provides secure HTTP proxy functionality for Project Forge applications. It allows your application to proxy requests to external services while maintaining security controls and consistent routing patterns.

Overview

This module enables applications to act as a secure HTTP proxy, forwarding requests to configured external services while:

⚠️ Security Notice: This module is marked as “dangerous” as it can expose your application to external services. Use with proper authentication and validation.

Key Features

Secure Proxying

URL Rewriting

Dynamic Service Management

Configuration

The proxy service is initialized with:

1
2
3
4
5
6
7
8
// Create proxy service with URL prefix and initial services
proxyService := proxy.NewService("/proxy", map[string]string{
"api": "http://localhost:8080",
"docs": "https://docs.example.com",
})

// Add to application state
as.Services.Proxy = proxyService

Usage

Basic Setup

  1. Initialize the service in your application startup:
proxy := proxy.NewService("/proxy", initialProxies)
  1. Wire up routes in your router configuration:
1
2
3
// Add proxy routes (typically in routes/proxy.go)
mux.HandleFunc("/proxy", clib.ProxyIndex)
mux.HandleFunc("/proxy/{svc}/{path:.*}", clib.ProxyHandle)

Managing Proxy Services

1
2
3
4
5
6
7
8
// Add a new service
proxyService.SetURL("newservice", "https://api.example.com")

// Remove a service
proxyService.Remove("oldservice")

// List all services
services := proxyService.List()

Request Flow

  1. Client makes request to /proxy/{service}/{path}
  2. Proxy service looks up the target URL for {service}
  3. Request is forwarded to {target_url}/{path}
  4. Response is processed and URLs are rewritten
  5. Modified response is returned to client

Security Considerations

Source Code

See Also