Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/01one/python-pages

Migrate Your Static Site to a Python-Powered Server
https://github.com/01one/python-pages

cloudflare-pages-alternative github-pages-alternative md-to-html python-server python-static-page python-tornado python-web static-page-generator static-pages static-server static-site-generation static-site-generator static-website

Last synced: 25 days ago
JSON representation

Migrate Your Static Site to a Python-Powered Server

Awesome Lists containing this project

README

        

# Migrate Your Static Site to a Python-Powered Server

## Why Host a Static Site with Python?

While platforms like GitHub Pages and Cloudflare Pages offer convenient hosting solutions, running your static site through a Python server provides several compelling advantages:

* **Complete Control**: Custom server logic allows you to implement specific routing rules, security measures, and content handling that may not be possible with hosted platforms easily
* **Flexible URL Management**: Implement custom URL schemes, redirects, and clean URLs exactly as you need them
* **Advanced MIME Type Support**: Handle any file type with custom MIME type definitions and content delivery rules
* **Server-Side Logic**: Easy integration of server-side features like analytics, logging, or dynamic content generation when needed
* **Development Environment**: Perfect for local development and testing, with the ability to exactly mirror your production environment
* **Custom Error Handling**: Implement specific error pages and fallback behaviors tailored to your needs
* **Performance Optimization**: Fine-tune caching, compression, and content delivery based on your specific requirements

Migrate your static site from Cloudflare Pages or GitHub Pages to a python-based custom server. Easily deploy your static site.

## Features of This Implementation

* **Custom MIME Type Support**: Includes additional MIME types for comprehensive file handling
* **Markdown Rendering**: Markdown files (`.md`) are automatically converted to HTML
* **Automatic Clean URL Handling**: Removes `.html` from URLs for a cleaner, more modern URL structure
* **404 Fallback**: Handles missing files with `404` error page
* **Lightweight**: Runs on Tornado, a lightweight Python web framework designed for high performance
* **Localhost Binding**: Specifically binds to `localhost` for security and simplicity during development and you can configure it with nginx

## Prerequisites

1. **Python Installed**: Ensure you have Python 3.7 or newer installed on your system
2. **Tornado Installed**: Install Tornado using pip with the following command:
```
pip install tornado
```
3. **Markdown Installed**: Install Python Markdown using pip with the following command:
```
pip install markdown
```
4. **Static Site Prepared**: Have your static site files ready in a folder (e.g., `static_site`)

## Steps to Host Your Static Site

### 1. just Clone or Download the Repository or Set Up the Server

Create a directory for your server and include the following Python script as `server.py`:

### 2. Place Your Static Files In the Static Folder

Place all your static site files (HTML, CSS, JS, images, etc.) into this folder. For example:

```
project-folder/
├── server.py
└── static_site/
├── index.html
├── about.html
├── styles.css
└── scripts.js
```

### 3. Run the Server

Start the server by running:
```
python server.py
```

The server will run on http://localhost:5000.

## Migration Tips

### From Cloudflare Pages or GitHub Pages

1. **Download Your Site**: Clone or download the static files of your site from your current hosting service
2. **Place in `static_site` Folder**: Move all your site files into the `static_site` directory created in step 2 above
3. **Test Locally**: Start the server and test that all links and assets load correctly
4. **Deploy to Production**: You can deploy this server to a production environment by exposing it on a public IP or a domain. Consider using a reverse proxy like Nginx or a cloud hosting service

## Troubleshooting

1. **File Not Found Errors**:
* Ensure the requested file exists in the `static_site` directory
* Check for typos in URLs or file names

2. **Port Already in Use**:
* Change the port in `server.py` from `5000` to another available port:


```
app.listen(8080, address="localhost")
```

Congratulations! You've successfully migrated your static site to a Tornado-based server. Enjoy the flexibility and simplicity of hosting your site with Python!