User Guide
This guide covers advanced usage patterns and best practices for Hostify.
Understanding Hostify
Hostify uses Cloudflare Tunnels to expose your local applications to the internet without requiring port forwarding or a public IP address. It handles all the complexity of:
Creating and managing Cloudflare tunnels
Configuring DNS records
Managing the cloudflared binary
Monitoring connection health
Cleaning up resources on shutdown
Hosting Modes
Hostify supports two hosting modes:
Existing Server Mode - Connect to an already-running local server
Static Files Mode - Serve static HTML/CSS/JS files
Existing Server Mode
Existing Server Mode MODE
Use this when you have an application already running locally (Flask, Node.js, PHP, etc.):
from hostify import Host
# Your app is running on port 3000
Host(domain="app.example.com", port=3000).serve()
Requirements:
Your application must be running before starting Hostify
The port must be accessible on localhost
Port must be between 1-65535
Static Files Mode
Static Files Mode MODE
- You have a static site (HTML/CSS/JS)
- You want zero config hosting
- You're using an old PC or local machine
This will serve your local ./public folder at mysite.example.com.
from hostify import Host
Host(
domain="mysite.example.com",
path="./public" # Directory containing index.html, etc.
).serve()
Features:
- 🚀 Starts a built-in HTTP server automatically
- 🎯 Finds an available port automatically
- 📄 Serves index.html as the default page
- 📦 Supports all static file types (HTML, CSS, JS, images, etc.)
Configuration Options
Domain Configuration
The domain must be:
A valid domain or subdomain
Already added to your Cloudflare account
Properly configured with Cloudflare nameservers
Examples:
# Subdomain
Host(domain="app.example.com", port=3000).serve()
# Nested subdomain
Host(domain="api.staging.example.com", port=8000).serve()
API Token Configuration
Three ways to provide your Cloudflare API token:
1. Environment Variable (Recommended):
export CF_API_TOKEN="your_token"
Host(domain="app.example.com", port=3000).serve()
2. Direct Parameter:
Host(
domain="app.example.com",
port=3000,
api_token="your_token"
).serve()
3. Configuration File:
Create a .env file and load it:
import os
from dotenv import load_dotenv
from hostify import Host
load_dotenv() # Loads CF_API_TOKEN from .env
Host(domain="app.example.com", port=3000).serve()
Advanced Patterns
Multiple Applications
Host multiple applications on different subdomains:
import threading
from hostify import Host
def host_app1():
Host(domain="app1.example.com", port=3000).serve()
def host_app2():
Host(domain="app2.example.com", port=4000).serve()
# Start both in separate threads
threading.Thread(target=host_app1).start()
threading.Thread(target=host_app2).start()
Warning
Each tunnel requires its own process. Make sure your applications are running on different ports.
Integration with Web Frameworks
Flask:
from flask import Flask
from hostify import Host
import threading
app = Flask(__name__)
@app.route('/')
def home():
return "Hello from Flask!"
if __name__ == '__main__':
# Start Flask
threading.Thread(
target=lambda: app.run(port=5000, debug=False)
).start()
# Host it
Host(domain="flask.example.com", port=5000).serve()
Django:
# In a separate script (host_django.py)
from hostify import Host
# Django dev server running on port 8000
Host(domain="django.example.com", port=8000).serve()
Run Django first:
# Terminal 1
python manage.py runserver
# Terminal 2
python host_django.py
FastAPI:
from fastapi import FastAPI
import uvicorn
from hostify import Host
import threading
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
if __name__ == "__main__":
# Start Uvicorn
threading.Thread(
target=lambda: uvicorn.run(app, host="127.0.0.1", port=8000)
).start()
# Host it
Host(domain="fastapi.example.com", port=8000).serve()
Production Deployment
For production use, consider:
Process Management: Use systemd, supervisor, or PM2 to keep Hostify running
Logging: Redirect output to log files
Monitoring: Monitor tunnel health and restart if needed
Security: Keep API tokens secure (use environment variables, not hardcoded)
Example systemd service:
[Unit]
Description=Hostify Tunnel for MyApp
After=network.target
[Service]
Type=simple
User=myuser
WorkingDirectory=/home/myuser/myapp
Environment="CF_API_TOKEN=your_token"
ExecStart=/usr/bin/python3 /home/myuser/myapp/host.py
Restart=always
[Install]
WantedBy=multi-user.target
Best Practices
Use Environment Variables for API tokens
Test Locally First before hosting publicly
Monitor Logs for connection issues
Use Subdomains for different environments (dev.example.com, staging.example.com)
Keep Hostify Updated with
pip install --upgrade hostifySecure Your Application - Hostify provides HTTPS, but you should still implement authentication
Security Considerations
HTTPS is Automatic: All traffic is encrypted via Cloudflare
Firewall Friendly: No inbound ports need to be opened
Token Security: Keep your Cloudflare API token secure
Application Security: Hostify doesn’t add authentication - secure your app!
Warning
Hosting makes your application publicly accessible. Ensure proper authentication and security measures are in place.
Performance Tips
Use Production Servers: For Python apps, use Gunicorn/uWSGI instead of development servers
Enable Caching: Configure Cloudflare caching rules for static assets
Monitor Resources: Old PCs may have limited resources - monitor CPU/RAM usage
Optimize Assets: Compress images and minify CSS/JS for faster loading
Troubleshooting
See the Troubleshooting guide for common issues and solutions.