Skip to content

Commit 1298644

Browse files
committed
Initial commit
1 parent 3e020d2 commit 1298644

File tree

17 files changed

+486
-0
lines changed

17 files changed

+486
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "BLM16/MicroServer",
3+
"image": "mcr.microsoft.com/devcontainers/python:3",
4+
"customizations": {
5+
"vscode": {
6+
"settings": {
7+
"python.defaultInterpreterPath": "${workspaceFolder}/venv",
8+
"python.terminal.activateEnvInCurrentTerminal": true,
9+
"python.terminal.executeInFileDir": true
10+
},
11+
"extensions": [
12+
"ms-python.python"
13+
]
14+
}
15+
},
16+
"onCreateCommand": ".devcontainer/on-create-command.sh"
17+
}

.devcontainer/on-create-command.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -e
3+
4+
python3 -m venv venv
5+
. venv/bin/activate
6+
pip install -U pip
7+
pip install -e .

.github/workflows/publish.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Publish
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
name: Build
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: 3.x
17+
18+
- name: Install pypa/build
19+
run: python3 -m pip install build --user
20+
21+
- name: Build wheel and tarball
22+
run: python3 -m build
23+
24+
- name: Store dist package
25+
uses: actions/upload-artifact@v3
26+
with:
27+
name: package-dist
28+
path: dist/
29+
30+
github-release:
31+
name: Sign the distribution and upload to GitHub Release
32+
needs:
33+
- publish-pypi
34+
runs-on: ubuntu-latest
35+
36+
permissions:
37+
contents: write
38+
id-token: write
39+
40+
steps:
41+
- name: Download all the dists
42+
uses: actions/download-artifact@v3
43+
with:
44+
name: package-dist
45+
path: dist/
46+
47+
- name: Sign dists with Sigstore
48+
uses: sigstore/gh-action-sigstore-python@v1.2.3
49+
with:
50+
inputs: >-
51+
./dist/*.tar.gz
52+
./dist/*.whl
53+
54+
- name: Create GitHub Release
55+
env:
56+
GITHUB_TOKEN: ${{ github.token }}
57+
run: >-
58+
gh release create
59+
'${{ github.ref_name }}'
60+
--repo '${{ github.repository }}'
61+
--notes ""
62+
63+
- name: Upload artifact signatures
64+
env:
65+
GITHUB_TOKEN: ${{ github.token }}
66+
run: >-
67+
gh release upload
68+
'${{ github.ref_name }}' dist/**
69+
--repo '${{ github.repository }}'
70+
71+
publish-pypi:
72+
name: Publish to PyPi
73+
if: startsWith(github.ref, 'refs/tags/')
74+
needs:
75+
- build
76+
runs-on: ubuntu-latest
77+
78+
environment:
79+
name: pypi
80+
url: https://pypi.org/p/BLM16-MicroServer
81+
82+
permissions:
83+
id-token: write
84+
85+
steps:
86+
- name: Download dists
87+
uses: actions/download-artifact@v3
88+
with:
89+
name: package-dist
90+
path: dist/
91+
92+
- name: Publish to PyPi
93+
uses: pypa/gh-action-pypi-publish@release/v1
94+
95+
publish-testpypi:
96+
name: Publish to TestPyPI
97+
needs:
98+
- build
99+
runs-on: ubuntu-latest
100+
101+
environment:
102+
name: testpypi
103+
url: https://test.pypi.org/p/BLM16-MicroServer
104+
105+
permissions:
106+
id-token: write
107+
108+
steps:
109+
- name: Download all the dists
110+
uses: actions/download-artifact@v3
111+
with:
112+
name: package-dist
113+
path: dist/
114+
115+
- name: Publish to TestPyPI
116+
uses: pypa/gh-action-pypi-publish@release/v1
117+
with:
118+
repository-url: https://test.pypi.org/legacy/

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Python: Current File",
6+
"type": "python",
7+
"request": "launch",
8+
"program": "${file}",
9+
"console": "integratedTerminal",
10+
"justMyCode": true,
11+
"cwd": "${fileDirname}",
12+
"purpose": ["debug-in-terminal"]
13+
}
14+
]
15+
}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# 1.0.0
2+
3+
2024-01-18
4+
5+
- GET capabilities
6+
- Custom routing

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Bradley Myers. All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# MicroServer
2+
3+
MicroServer is a lightweight Python webserver with minimal overhead and no external dependencies
4+
MicroServer provides complete flexibility by leaving all data processing and templating to the user.
5+
6+
```py
7+
from microserver import MicroServer, Response
8+
9+
server = MicroServer()
10+
11+
# Configures the route / to be handled by the home function.
12+
@server.route('/')
13+
def home():
14+
data = server.load_view('index.html')
15+
mime = 'text/html'
16+
return Response(data, mime)
17+
18+
# Configures all 404 errors to be handled by the e404 function.
19+
@server.errorhandler(404)
20+
def e404():
21+
data = server.load_view('404.html')
22+
mime = 'text/html'
23+
return Response(data, mime)
24+
25+
# Starts the server on the given host and port.
26+
server.start('localhost', 8080)
27+
```

examples/basic_routing/main.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from microserver import MicroServer, Response
2+
3+
HOST = 'localhost'
4+
PORT = 8080
5+
6+
server = MicroServer()
7+
8+
# Configures the route / to be handled by the home function.
9+
# Returns a Response with the contents of views/index.html.
10+
@server.route('/')
11+
def home():
12+
data = server.load_view('index.html')
13+
mime = 'text/html'
14+
return Response(data, mime)
15+
16+
# Configures all 404 errors to be handled by the e404 function.
17+
# Returns a Response with the contents of view/404.html.
18+
@server.errorhandler(404)
19+
def e404():
20+
data = server.load_view('404.html')
21+
mime = 'text/html'
22+
return Response(data, mime)
23+
24+
# Starts the server on the given host and port.
25+
server.start(HOST, PORT)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>404 - Basic Routing Example</title>
7+
</head>
8+
<body>
9+
<h1>404 Not Found</h1>
10+
<p>That URL doesn't exist.</p>
11+
<a href="/">Home</a>
12+
</body>
13+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Basic Routing Example</title>
7+
</head>
8+
<body>
9+
<h1>Basic Routing Example</h1>
10+
<p>Welcome from index.html!</p>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)