This project is an asynchronous server built using Python's asyncio.create_server
,
designed for efficient request handling. It features a simple router-based request dispatcher,
static file serving, and logging configuration.
The server can handle both GET
and POST
requests and allows for easy route registration.
- Async server powered by
asyncio.create_server
- Customizable logging via log levels (debug, info, warning, error)
- Static file serving (optional)
- Simple router-based dispatching for request handling, configured in
locations.ini
- Error handling for 404 (Not Found), 405 (Method Not Allowed), and 500 (Internal Server Error)
- Flexible configuration for host, port, and log levels
The server starts on 0.0.0.0:8079
by default. You can run the server with the following command:
python -m yapas
You can customize the server's host, port, static file path, and logging level with the following command-line options:
python -m yapas --host <host_ip> --port <port_number> --log_level <log_level>
python -m yapas --host 127.0.0.1 --port 8080 --log_level info --use_proxy
host
: IP address of the server (default:0.0.0.0
)port
: Port to bind the server to (default:8079
)log_level
: Logging level (debug
,info
,warning
,error
) (default:debug
)use_proxy
: use or not pre-set reverse proxy (seelocations.ini
), ensurelocalhost:8000
is listened, if this parameter is set
- /index - static page
- /metrics - shows some metrics info in terminal
- /restart - restarts the server
The server supports custom error handling for common HTTP errors:
404 Not Found
: Raised if a route is not found.405 Method Not Allowed
: Raised if the requested method is not supported by the route.500 Internal Server Error
: Raised for any unhandled exceptions.
- Basic in-memory caching is implemented for static content.
- Server listens signals to gracefully terminate (
SIGTERM
) or restart (SIGHUP
).
- Server supports a basic reverse proxy feature to forward requests to another backend server,
retaining client headers such as
User-Agent
andCookies
.
- SSL/TLS Support: Add HTTPS support using Python's built-in
ssl
module to enable secure communication over SSL/TLS. - Round Robin Load Balancing: Extend reverse proxying to support multiple backend servers with a round-robin load balancing algorithm for better distribution of incoming requests.
This project is licensed under the MIT License.