Skip to main content

Host applications from old PCs using Cloudflare Tunnels

Project description

Hostify - Host from Anywhere

Turn old PCs into production servers with one line of code.

Host applications from old PCs or home machines using Cloudflare Tunnels. No port forwarding, no dynamic DNS, just pure simplicity.

PyPI version Python License: MIT


๐Ÿš€ Quick Start

from hostify import Host

# Host your app in one line
Host(domain="app.example.com", port=3000).serve()

That's it! Your app is now live at https://app.example.com with automatic HTTPS.


๐Ÿ“ฆ Installation

pip install hostify

Requirements:

  • Python >= 3.9
  • Cloudflare account with a domain
  • Cloudflare API token (setup guide)

๐ŸŽฏ Features

  • โœ… One-line API - Simple and intuitive
  • โœ… Automatic HTTPS - Secure by default via Cloudflare
  • โœ… No Port Forwarding - Works behind NAT/firewalls
  • โœ… Cross-Platform - Windows, Linux, macOS
  • โœ… Static Files - Built-in HTTP server
  • โœ… Existing Servers - Works with Flask, Node, PHP, etc.
  • โœ… Auto-Cleanup - Graceful shutdown with Ctrl+C
  • โœ… Auto-Recovery - Restarts on connection issues

๐Ÿ’ก Use Cases

  1. Development - Share local dev server with team
  2. Demos - Show clients your work without deployment
  3. Old Hardware - Turn old PCs into production servers
  4. Home Labs - Host personal projects from home
  5. Testing - Test webhooks and integrations locally

๐Ÿ“– Usage Examples

Example 1: Host Static Files

from hostify import Host

# Serve static HTML/CSS/JS files
Host(
    domain="mysite.example.com",
    path="./public"
).serve()

Example 2: Host Flask App

from flask import Flask
from hostify import Host

app = Flask(__name__)

@app.route('/')
def home():
    return "<h1>Hello World!</h1>"

if __name__ == '__main__':
    # Start Flask in background
    import threading
    threading.Thread(target=lambda: app.run(port=5000)).start()
    
    # Host it with hostify
    Host(domain="flask.example.com", port=5000).serve()

Example 3: Host Existing Server

from hostify import Host

# Your Node.js/PHP/Python server is already running on port 3000
Host(domain="app.example.com", port=3000).serve()

Example 4: Custom API Token

from hostify import Host

Host(
    domain="app.example.com",
    port=8000,
    api_token="your_cloudflare_api_token"
).serve()

๐Ÿ”ง Setup Guide

Step 1: Install Hostify

pip install hostify

Step 2: Get Cloudflare API Token

  1. Go to Cloudflare API Tokens
  2. Click "Create Token"
  3. Use "Edit Cloudflare Zero Trust" template or create custom token with:
    • Account โ†’ Cloudflare Tunnel โ†’ Edit
    • Zone โ†’ DNS โ†’ Edit
    • Zone โ†’ Zone โ†’ Read
  4. Copy the token

Detailed guide: CLOUDFLARE_SETUP.md

Step 3: Set Environment Variable

Windows (PowerShell):

$env:CF_API_TOKEN="your_token_here"

Linux/Mac:

export CF_API_TOKEN="your_token_here"

Permanent (add to profile):

# Linux/Mac: Add to ~/.bashrc or ~/.zshrc
echo 'export CF_API_TOKEN="your_token_here"' >> ~/.bashrc

# Windows: Use System Environment Variables
setx CF_API_TOKEN "your_token_here"

Step 4: Add Domain to Cloudflare

Make sure your domain is added to Cloudflare and nameservers are configured.

Step 5: Run Hostify

from hostify import Host

Host(domain="app.yourdomain.com", port=3000).serve()

๐ŸŽจ Live Demos

Check out these live examples hosted with hostify:


๐Ÿ“š API Reference

Host Class

Host(
    domain: str,           # Required: Full domain (e.g., "app.example.com")
    port: int = None,      # Port of existing server (mutually exclusive with path)
    path: str = None,      # Path to static files (mutually exclusive with port)
    api_token: str = None  # Optional: Cloudflare API token
)

Methods:

  • .serve() - Start hosting (blocks until Ctrl+C)

Parameters:

  • domain (required): Full domain or subdomain (e.g., "app.example.com")
  • port (optional): Port number where your app is running (1-65535)
  • path (optional): Path to directory with static files
  • api_token (optional): Cloudflare API token (defaults to CF_API_TOKEN env var)

Note: You must specify either port OR path, not both.


๐Ÿ” How It Works

  1. Creates Cloudflare Tunnel - Establishes secure connection
  2. Configures DNS - Automatically creates CNAME record
  3. Routes Traffic - Configures tunnel to route domain to your local server
  4. Manages Binary - Downloads and runs cloudflared automatically
  5. Monitors Connection - Auto-restarts on failures
  6. Cleans Up - Removes all resources on Ctrl+C

๐Ÿ› ๏ธ Troubleshooting

"No server found on port X"

Solution: Make sure your application is running before starting hostify.

# Terminal 1: Start your app
python app.py

# Terminal 2: Host it
python host.py

"Zone not found for domain"

Solution: Ensure your domain is added to Cloudflare and nameservers are configured.

"No Cloudflare accounts found"

Solution: Check your API token has the correct permissions:

  • Account โ†’ Cloudflare Tunnel โ†’ Edit
  • Zone โ†’ DNS โ†’ Edit
  • Zone โ†’ Zone โ†’ Read

Site shows 404

Solution: Wait 30-60 seconds for tunnel to fully connect and DNS to propagate.

"Cloudflare API token not found"

Solution: Set the CF_API_TOKEN environment variable or pass api_token parameter.


๐Ÿงช Testing

Run the comprehensive test suite:

python tests/test_suite.py

Expected output:

Results: 9/9 tests passed (100%)
All tests passed! Library is ready for publication.

๐Ÿ“ Project Structure

hostify/
โ”œโ”€โ”€ hostify/              # Main package
โ”‚   โ”œโ”€โ”€ __init__.py      # Package exports
โ”‚   โ”œโ”€โ”€ cloudflare.py    # Cloudflare API wrapper
โ”‚   โ”œโ”€โ”€ cloudflared.py   # Binary manager
โ”‚   โ”œโ”€โ”€ host.py          # Main Host class
โ”‚   โ””โ”€โ”€ utils.py         # Utilities
โ”œโ”€โ”€ examples/            # Usage examples
โ”œโ”€โ”€ tests/               # Test suite
โ””โ”€โ”€ docs/                # Documentation

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Built on Cloudflare Tunnels
  • Inspired by the need for simple, accessible hosting solutions

๐Ÿ“ž Support


๐Ÿ”ฎ Roadmap

  • Multiple domain support
  • Web dashboard for management
  • Authentication system
  • Custom cloudflared configuration
  • Load balancing
  • Health checks and monitoring
  • CLI tool

Made with โค๏ธ for developers who want to host from anywhere


โญ Star History

If you find this project useful, please consider giving it a star on GitHub!

Star History Chart

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hostify-0.1.1.tar.gz (33.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hostify-0.1.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file hostify-0.1.1.tar.gz.

File metadata

  • Download URL: hostify-0.1.1.tar.gz
  • Upload date:
  • Size: 33.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for hostify-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1e0ce5520d1e5ac3cdbfac009faf2124aa65ef40b14605a743246b2b22be29df
MD5 6635df264a1a4ea3397c3031f94357b5
BLAKE2b-256 d907334078718c4bed0cf211b1a5d85c84dd0ce334be0b6ed30a8a5febd72a37

See more details on using hashes here.

File details

Details for the file hostify-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hostify-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for hostify-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e5839e31d3a393f4c82c5b78f0f7ac160e0e807d05db5003ddb9be585e60e25a
MD5 28ed26c57602b5401e9afa55e62b3b75
BLAKE2b-256 b721a9f143d3ba34b8d8ae2ba0f69df33815100b838b1f4317cefd44c82902f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page