Nexom 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nexom/__init__.py +19 -0
- nexom/__main__.py +61 -0
- nexom/assets/error_page/error.html +44 -0
- nexom/assets/server/config.py +27 -0
- nexom/assets/server/gunicorn.conf.py +16 -0
- nexom/assets/server/pages/__init__.py +3 -0
- nexom/assets/server/pages/__pycache__/__init__.cpython-313.pyc +0 -0
- nexom/assets/server/pages/_templates.py +11 -0
- nexom/assets/server/pages/default.py +10 -0
- nexom/assets/server/pages/document.py +10 -0
- nexom/assets/server/router.py +18 -0
- nexom/assets/server/static/dog.jpeg +0 -0
- nexom/assets/server/static/style.css +39 -0
- nexom/assets/server/templates/base.html +18 -0
- nexom/assets/server/templates/default.html +7 -0
- nexom/assets/server/templates/document.html +169 -0
- nexom/assets/server/templates/footer.html +3 -0
- nexom/assets/server/templates/header.html +3 -0
- nexom/assets/server/wsgi.py +30 -0
- nexom/buildTools/__init__.py +0 -0
- nexom/buildTools/build.py +99 -0
- nexom/core/__init__.py +1 -0
- nexom/core/error.py +149 -0
- nexom/engine/__init__.py +1 -0
- nexom/engine/object_html_render.py +224 -0
- nexom/web/__init__.py +5 -0
- nexom/web/cookie.py +73 -0
- nexom/web/http_status_codes.py +72 -0
- nexom/web/middleware.py +51 -0
- nexom/web/path.py +125 -0
- nexom/web/request.py +62 -0
- nexom/web/response.py +146 -0
- nexom/web/template.py +115 -0
- nexom-0.1.3.dist-info/METADATA +168 -0
- nexom-0.1.3.dist-info/RECORD +39 -0
- nexom-0.1.3.dist-info/WHEEL +5 -0
- nexom-0.1.3.dist-info/entry_points.txt +2 -0
- nexom-0.1.3.dist-info/licenses/LICENSE +21 -0
- nexom-0.1.3.dist-info/top_level.txt +1 -0
nexom/web/request.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Mapping
|
|
4
|
+
from http.cookies import SimpleCookie
|
|
5
|
+
|
|
6
|
+
from .cookie import RequestCookies
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
WSGIEnviron = Mapping[str, Any]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Request:
|
|
13
|
+
"""
|
|
14
|
+
Represents an HTTP request constructed from a WSGI environ.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, environ: WSGIEnviron) -> None:
|
|
18
|
+
self.environ: WSGIEnviron = environ
|
|
19
|
+
|
|
20
|
+
self.method: str = environ.get("REQUEST_METHOD", "GET")
|
|
21
|
+
self.path: str = environ.get("PATH_INFO", "").lstrip("/")
|
|
22
|
+
self.query: str = environ.get("QUERY_STRING", "")
|
|
23
|
+
self.headers: dict[str, str] = {
|
|
24
|
+
k[5:].replace("_", "-"): v
|
|
25
|
+
for k, v in environ.items()
|
|
26
|
+
if k.startswith("HTTP_")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
self.cookie: RequestCookies | None = self._parse_cookies()
|
|
30
|
+
self._body: bytes | None = None
|
|
31
|
+
|
|
32
|
+
def _parse_cookies(self) -> RequestCookies | None:
|
|
33
|
+
cookie_header = self.environ.get("HTTP_COOKIE")
|
|
34
|
+
if not cookie_header:
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
simple_cookie = SimpleCookie()
|
|
38
|
+
simple_cookie.load(cookie_header)
|
|
39
|
+
|
|
40
|
+
cookies = {
|
|
41
|
+
key: morsel.value
|
|
42
|
+
for key, morsel in simple_cookie.items()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
rc = RequestCookies(**cookies)
|
|
46
|
+
rc.default = None
|
|
47
|
+
return rc
|
|
48
|
+
|
|
49
|
+
def read_body(self) -> bytes:
|
|
50
|
+
"""
|
|
51
|
+
Read and cache the request body.
|
|
52
|
+
"""
|
|
53
|
+
if self._body is not None:
|
|
54
|
+
return self._body
|
|
55
|
+
|
|
56
|
+
length = int(self.environ.get("CONTENT_LENGTH") or 0)
|
|
57
|
+
if length <= 0:
|
|
58
|
+
self._body = b""
|
|
59
|
+
return self._body
|
|
60
|
+
|
|
61
|
+
self._body = self.environ["wsgi.input"].read(length)
|
|
62
|
+
return self._body
|
nexom/web/response.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Iterable, Optional
|
|
4
|
+
from importlib import resources
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
from .http_status_codes import http_status_codes
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Header = tuple[str, str]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Response:
|
|
14
|
+
"""
|
|
15
|
+
Represents an HTTP response.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
body: str | bytes = b"",
|
|
21
|
+
status: int = 200,
|
|
22
|
+
headers: Iterable[Header] | None = None,
|
|
23
|
+
cookie: str | None = None,
|
|
24
|
+
content_type: str = "text/html",
|
|
25
|
+
charset: str = "utf-8",
|
|
26
|
+
include_charset: bool = False
|
|
27
|
+
) -> None:
|
|
28
|
+
self.charset: str = charset
|
|
29
|
+
self.include_charset: bool = include_charset
|
|
30
|
+
|
|
31
|
+
if isinstance(body, str):
|
|
32
|
+
self.body: bytes = body.encode(charset)
|
|
33
|
+
self.is_text: bool = True
|
|
34
|
+
else:
|
|
35
|
+
self.body = body
|
|
36
|
+
self.is_text = False
|
|
37
|
+
|
|
38
|
+
self.status_code: int = status
|
|
39
|
+
|
|
40
|
+
from .http_status_codes import http_status_codes
|
|
41
|
+
self.status_text: str = f"{status} {http_status_codes.get(status, '')}".strip()
|
|
42
|
+
|
|
43
|
+
ct = content_type
|
|
44
|
+
if include_charset and (ct.startswith("text/") or ct == "application/json"):
|
|
45
|
+
ct = f"{ct}; charset={charset}"
|
|
46
|
+
|
|
47
|
+
self.headers: list[Header] = list(headers) if headers else [("Content-Type", ct)]
|
|
48
|
+
|
|
49
|
+
if cookie:
|
|
50
|
+
self.headers.append(("Set-Cookie", cookie))
|
|
51
|
+
|
|
52
|
+
def __iter__(self):
|
|
53
|
+
"""
|
|
54
|
+
Allow Response to be returned directly from WSGI apps.
|
|
55
|
+
"""
|
|
56
|
+
yield self.body
|
|
57
|
+
|
|
58
|
+
class HtmlResponse(Response):
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
body: str | bytes = b"",
|
|
62
|
+
status: int = 200,
|
|
63
|
+
headers: Iterable[Header] | None = None,
|
|
64
|
+
cookie: str | None = None,
|
|
65
|
+
*,
|
|
66
|
+
charset: str = "utf-8",
|
|
67
|
+
include_charset: bool = True,
|
|
68
|
+
) -> None:
|
|
69
|
+
super().__init__(
|
|
70
|
+
body=body,
|
|
71
|
+
status=status,
|
|
72
|
+
headers=headers,
|
|
73
|
+
cookie=cookie,
|
|
74
|
+
content_type="text/html",
|
|
75
|
+
charset=charset,
|
|
76
|
+
include_charset=include_charset,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class JsonResponse(Response):
|
|
81
|
+
def __init__(
|
|
82
|
+
self,
|
|
83
|
+
body: Optional[dict] = None,
|
|
84
|
+
status: int = 200,
|
|
85
|
+
headers: Iterable[Header] | None = None,
|
|
86
|
+
cookie: str | None = None,
|
|
87
|
+
*,
|
|
88
|
+
charset: str = "utf-8",
|
|
89
|
+
include_charset: bool = True,
|
|
90
|
+
) -> None:
|
|
91
|
+
if body is None:
|
|
92
|
+
body = {}
|
|
93
|
+
|
|
94
|
+
content_type = "application/json"
|
|
95
|
+
if include_charset:
|
|
96
|
+
content_type = f"{content_type}; charset={charset}"
|
|
97
|
+
|
|
98
|
+
jb = json.dumps(body, ensure_ascii=False).encode(charset)
|
|
99
|
+
|
|
100
|
+
super().__init__(
|
|
101
|
+
body=jb,
|
|
102
|
+
status=status,
|
|
103
|
+
headers=headers,
|
|
104
|
+
cookie=cookie,
|
|
105
|
+
content_type=content_type,
|
|
106
|
+
charset=charset,
|
|
107
|
+
include_charset=False, # ここは自前で付けたからFalse
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
class Redirect(Response):
|
|
111
|
+
"""
|
|
112
|
+
HTTP redirect response (302).
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
def __init__(self, location: str) -> None:
|
|
116
|
+
super().__init__(
|
|
117
|
+
body=b"",
|
|
118
|
+
status=302,
|
|
119
|
+
headers=[("Location", location)],
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class ErrorResponse(Response):
|
|
124
|
+
"""
|
|
125
|
+
HTML error response rendered from template.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
def __init__(self, status: int, message: str) -> None:
|
|
129
|
+
html = self._render(status, message)
|
|
130
|
+
super().__init__(html, status=status)
|
|
131
|
+
|
|
132
|
+
@staticmethod
|
|
133
|
+
def _render(status: int, message: str) -> str:
|
|
134
|
+
status_text = f"{status} {http_status_codes.get(status, '')}".strip()
|
|
135
|
+
|
|
136
|
+
template = (
|
|
137
|
+
resources.files("nexom.assets.error_page")
|
|
138
|
+
.joinpath("error.html")
|
|
139
|
+
.read_text(encoding="utf-8")
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
template
|
|
144
|
+
.replace("__STATUS__", status_text)
|
|
145
|
+
.replace("__MESSAGE__", message)
|
|
146
|
+
)
|
nexom/web/template.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from ..engine.object_html_render import HTMLDoc, HTMLDocLib, ObjectHTML
|
|
9
|
+
from ..core.error import TemplateNotFoundError, TemplateInvalidNameError, TemplatesNotDirError
|
|
10
|
+
|
|
11
|
+
_SEG_RE = re.compile(r"^[A-Za-z0-9_]+$")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True)
|
|
15
|
+
class TemplateEntry:
|
|
16
|
+
name: str
|
|
17
|
+
path: Path
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class _TemplateAccessor:
|
|
21
|
+
"""
|
|
22
|
+
Callable attribute-chain proxy.
|
|
23
|
+
|
|
24
|
+
Examples:
|
|
25
|
+
templates.default(title="x") -> templates.render("default", title="x")
|
|
26
|
+
templates.layout.base(title="x") -> templates.render("layout.base", title="x")
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(self, templates: ObjectHTMLTemplates, name: str) -> None: # type: ignore[name-defined]
|
|
30
|
+
self._templates = templates
|
|
31
|
+
self._name = name
|
|
32
|
+
|
|
33
|
+
def __getattr__(self, part: str) -> _TemplateAccessor:
|
|
34
|
+
if not _SEG_RE.match(part):
|
|
35
|
+
# Attribute access only supports valid segments by design.
|
|
36
|
+
raise AttributeError(part)
|
|
37
|
+
return _TemplateAccessor(self._templates, f"{self._name}.{part}")
|
|
38
|
+
|
|
39
|
+
def __call__(self, **kwargs: str) -> str:
|
|
40
|
+
return self._templates.render(self._name, **kwargs)
|
|
41
|
+
|
|
42
|
+
def __repr__(self) -> str:
|
|
43
|
+
return f"<TemplateAccessor name='{self._name}'>"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ObjectHTMLTemplates:
|
|
47
|
+
"""
|
|
48
|
+
Loads all *.html templates under base_dir and renders them using ObjectHTML.
|
|
49
|
+
|
|
50
|
+
Public API:
|
|
51
|
+
render("a.b", **kwargs) -> str
|
|
52
|
+
|
|
53
|
+
Sugar:
|
|
54
|
+
templates.a.b(**kwargs) -> render("a.b", **kwargs)
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
def __init__(self, base_dir: str) -> None:
|
|
58
|
+
self.base_dir = str(base_dir)
|
|
59
|
+
self._base_path = Path(self.base_dir).resolve()
|
|
60
|
+
|
|
61
|
+
if not self._base_path.exists() or not self._base_path.is_dir():
|
|
62
|
+
raise TemplatesNotDirError(self.base_dir)
|
|
63
|
+
|
|
64
|
+
lib = HTMLDocLib()
|
|
65
|
+
for entry in self._scan_templates(self._base_path):
|
|
66
|
+
html_text = entry.path.read_text(encoding="utf-8")
|
|
67
|
+
lib.append(HTMLDoc(entry.name, html_text))
|
|
68
|
+
|
|
69
|
+
self._engine = ObjectHTML(lib=lib)
|
|
70
|
+
|
|
71
|
+
def __getattr__(self, name: str) -> _TemplateAccessor:
|
|
72
|
+
# Called only when normal attribute lookup fails.
|
|
73
|
+
if not _SEG_RE.match(name):
|
|
74
|
+
raise AttributeError(name)
|
|
75
|
+
return _TemplateAccessor(self, name)
|
|
76
|
+
|
|
77
|
+
def render(self, name: str, **kwargs: str) -> str:
|
|
78
|
+
doc = self._engine.lib.get(name)
|
|
79
|
+
if not doc:
|
|
80
|
+
raise TemplateNotFoundError(name)
|
|
81
|
+
return self._engine.render(name, **kwargs)
|
|
82
|
+
|
|
83
|
+
def _scan_templates(self, root: Path) -> list[TemplateEntry]:
|
|
84
|
+
entries: list[TemplateEntry] = []
|
|
85
|
+
|
|
86
|
+
for path in root.rglob("*.html"):
|
|
87
|
+
if not path.is_file():
|
|
88
|
+
continue
|
|
89
|
+
|
|
90
|
+
rel = path.relative_to(root)
|
|
91
|
+
name = self._path_to_template_name(rel)
|
|
92
|
+
entries.append(TemplateEntry(name=name, path=path))
|
|
93
|
+
|
|
94
|
+
return entries
|
|
95
|
+
|
|
96
|
+
def _path_to_template_name(self, rel_path: Path) -> str:
|
|
97
|
+
parts = list(rel_path.parts)
|
|
98
|
+
if not parts:
|
|
99
|
+
raise TemplateInvalidNameError(str(rel_path))
|
|
100
|
+
|
|
101
|
+
filename = parts[-1]
|
|
102
|
+
if not filename.endswith(".html"):
|
|
103
|
+
raise TemplateInvalidNameError(str(rel_path))
|
|
104
|
+
|
|
105
|
+
stem = filename[:-5]
|
|
106
|
+
dir_parts = parts[:-1]
|
|
107
|
+
|
|
108
|
+
for seg in dir_parts:
|
|
109
|
+
if not _SEG_RE.match(seg):
|
|
110
|
+
raise TemplateInvalidNameError(str(rel_path))
|
|
111
|
+
|
|
112
|
+
if not _SEG_RE.match(stem):
|
|
113
|
+
raise TemplateInvalidNameError(str(rel_path))
|
|
114
|
+
|
|
115
|
+
return ".".join([*dir_parts, stem])
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Nexom
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Lightweight Python Web Framework (WSGI)
|
|
5
|
+
Author: TouriAida
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 TouriAida
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://nexom.ceez7.com
|
|
29
|
+
Project-URL: Repository, https://github.com/ait913/Nexom
|
|
30
|
+
Project-URL: Issues, https://github.com/ait913/Nexom/issues
|
|
31
|
+
Keywords: wsgi,web,framework
|
|
32
|
+
Requires-Python: >=3.10
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Nexom
|
|
39
|
+
Lightweight Python Web Framework (WSGI)
|
|
40
|
+
|
|
41
|
+
Nexomは短いコードで最低限動作し、シンプルで理解のしやすい設計・構造を目指しています。
|
|
42
|
+
また細かい仕様も変更でき、多様な処理に対応します。
|
|
43
|
+
|
|
44
|
+
## はじめる
|
|
45
|
+
最初のサーバーを起動するには、3つの手順が必要です。
|
|
46
|
+
|
|
47
|
+
1. ディレクトリを作成
|
|
48
|
+
2. nexomをpipでインストール、サーバーのビルド
|
|
49
|
+
3. 起動
|
|
50
|
+
|
|
51
|
+
### 1.ディレクトリの作成
|
|
52
|
+
**準備**
|
|
53
|
+
用意していない場合はディレクトリを作成し、仮想環境も準備てください
|
|
54
|
+
```
|
|
55
|
+
mkdir sample
|
|
56
|
+
cd sample
|
|
57
|
+
|
|
58
|
+
python -m venv venv
|
|
59
|
+
source venv/bin/activate
|
|
60
|
+
```
|
|
61
|
+
### 2.npipでインストール、サーバーのビルド
|
|
62
|
+
**インストール**
|
|
63
|
+
nexomをインストールします。
|
|
64
|
+
※まだベータ版のため、最新のバージョンを確認してください。
|
|
65
|
+
```
|
|
66
|
+
pip install nexom==0.1.4
|
|
67
|
+
```
|
|
68
|
+
**テンプレートサーバーのビルド**
|
|
69
|
+
サーバーを置きたいディレクトリ上で、以下のコマンドを実行してください(sampleは自由)
|
|
70
|
+
```
|
|
71
|
+
python -m nexom build-server sample
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3.起動
|
|
75
|
+
以下のコマンドを起動します。
|
|
76
|
+
```
|
|
77
|
+
gunicorn wsgi:app
|
|
78
|
+
```
|
|
79
|
+
ブラウザからアクセスできるようになります。
|
|
80
|
+
デフォルトのポートは8080です。
|
|
81
|
+
[httpls://localhost:8080](httpls://localhost:8080)
|
|
82
|
+
ポートなどの設定は `config.py` から変更してください。
|
|
83
|
+
|
|
84
|
+
## Nginx等使用して外部公開する
|
|
85
|
+
`config.py` で指定したポートにプロキシしてください。
|
|
86
|
+
```
|
|
87
|
+
server {
|
|
88
|
+
listen 443 ssl;
|
|
89
|
+
server_name nexom.ceez7.com;
|
|
90
|
+
|
|
91
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
92
|
+
|
|
93
|
+
location / {
|
|
94
|
+
proxy_pass http://localhost:8080;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Systemdに登録して自動起動する
|
|
100
|
+
**Ubuntuの場合**
|
|
101
|
+
1. `/etc/systemd/system` に、 `your_server_name.service` を作成します。
|
|
102
|
+
2. `your_server_name.service` に以下を書き込みます。(これは一例です。環境に合わせて設定してください。)
|
|
103
|
+
|
|
104
|
+
サーバーのディレクトリが `/home/ubuntu/nexom` にある場合
|
|
105
|
+
```
|
|
106
|
+
[Unit]
|
|
107
|
+
Description=Nexom Web Freamework
|
|
108
|
+
After=network.target
|
|
109
|
+
|
|
110
|
+
[Service]
|
|
111
|
+
User=www-data
|
|
112
|
+
Group=www-data
|
|
113
|
+
WorkingDirectory=/home/ubuntu/nexom
|
|
114
|
+
Environment="/home/ubuntu/nexom/venv/bin"
|
|
115
|
+
ExecStart=/home/ubuntu/nexom/venv/bin/gunicorn wsgi:app
|
|
116
|
+
[Install]
|
|
117
|
+
WantedBy=multi-user.target
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
以下のコマンドを実行します
|
|
121
|
+
```
|
|
122
|
+
sudo systemd daemon-reload
|
|
123
|
+
sudo systemd enable your_server_name
|
|
124
|
+
sudo systemd start your_server_name
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### テンプレートユニットを活用して複数のサーバーを効率的に管理
|
|
128
|
+
以下の構成でサーバーが建てられていたとします。
|
|
129
|
+
```
|
|
130
|
+
/home/ubuntu/BananaProject/
|
|
131
|
+
└─ web/
|
|
132
|
+
├─ banana1 (Nexomサーバー)/
|
|
133
|
+
│ └─ wsgi.py
|
|
134
|
+
├─ banana2 (Nexomサーバー)/
|
|
135
|
+
│ └─ wsgi.py
|
|
136
|
+
└─ banana3 (Nexomサーバー)/
|
|
137
|
+
└─ wsgi.py
|
|
138
|
+
```
|
|
139
|
+
この構成の場合、テンプレートユニットを活用し .service ファイルを一枚にまとめられます。
|
|
140
|
+
|
|
141
|
+
`/etc/systemd/system/banana-project@.service`
|
|
142
|
+
```
|
|
143
|
+
[Unit]
|
|
144
|
+
Description=Nexom Web Server (%i)
|
|
145
|
+
After=network.target
|
|
146
|
+
|
|
147
|
+
[Service]
|
|
148
|
+
User=www-data
|
|
149
|
+
Group=www-data
|
|
150
|
+
WorkingDirectory=/home/ubuntu/BananaProject/web/%i
|
|
151
|
+
Environment="/home/ubuntu/BananaProject/web/%i/venv/bin"
|
|
152
|
+
ExecStart=/home/ubuntu/BananaProject/web/%i/venv/bin/gunicorn wsgi:app
|
|
153
|
+
[Install]
|
|
154
|
+
WantedBy=multi-user.target
|
|
155
|
+
```
|
|
156
|
+
```
|
|
157
|
+
sudo systemd daemon-reload
|
|
158
|
+
|
|
159
|
+
sudo systemd enable banana-project@banana1
|
|
160
|
+
sudo systemd enable banana-project@banana2
|
|
161
|
+
sudo systemd enable banana-project@banana3
|
|
162
|
+
|
|
163
|
+
sudo systemd start banana-project@banana1
|
|
164
|
+
sudo systemd start banana-project@banana2
|
|
165
|
+
sudo systemd start banana-project@banana3
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
2026 1/24
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
nexom/__init__.py,sha256=tkqlHy7lHeCM4OuTb0GJZO3zopx6RcnpdMZE9E6g0_4,367
|
|
2
|
+
nexom/__main__.py,sha256=3W07j3zeXDxh8nmsAN0THLb9tVEB3Gjc2CNA1uYSB4Y,1949
|
|
3
|
+
nexom/assets/error_page/error.html,sha256=KlNyr-57wCEkp9ICSHTAmq4-6mQ0idbI2zgsmBx3MRw,1224
|
|
4
|
+
nexom/assets/server/config.py,sha256=3bWgwlS394JwFSDHfuZasgXPdtJVzSvT99kqCMT_2Zs,509
|
|
5
|
+
nexom/assets/server/gunicorn.conf.py,sha256=NedfqQFONa_p53zevgfRHrypu7aBCc6nCMeiEN1_BtM,377
|
|
6
|
+
nexom/assets/server/router.py,sha256=AxkoOJRE1lRmsA8Xve8RbvCZs6UleEQ4cbP2DzimGrQ,416
|
|
7
|
+
nexom/assets/server/wsgi.py,sha256=CiJJDWibh73a1wkCSuALoWDJ3u8fDDbbrR1bkurNgWE,743
|
|
8
|
+
nexom/assets/server/pages/__init__.py,sha256=DlX9iwM39JaMKfzK4mbgjE2uVMX3ax0wd2mCVnpg0b4,61
|
|
9
|
+
nexom/assets/server/pages/_templates.py,sha256=g77QjqMS9--Pw1P4mNCC2KMyiQI0kKo02ENwgIdE8dU,320
|
|
10
|
+
nexom/assets/server/pages/default.py,sha256=_XCNtj7Z57volVIS4KBhps9TQPYiflPBTv8v3GH2SYM,257
|
|
11
|
+
nexom/assets/server/pages/document.py,sha256=R7r8zBDBfv0vtr82TFcGb60MesKVqDihdGFt03eppVc,245
|
|
12
|
+
nexom/assets/server/pages/__pycache__/__init__.cpython-313.pyc,sha256=O03yzGGSKHVUeAqQVULe0-He2mBqkcVb_UwFF_esNUw,276
|
|
13
|
+
nexom/assets/server/static/dog.jpeg,sha256=qGEhcg48FxRLRISzbmXvw1qvfbdluC_ukM8ZrHg7_XE,6559
|
|
14
|
+
nexom/assets/server/static/style.css,sha256=mDKNWue0uRLdWB0w1RsMSn6h3tHsuTVLuk3xOOJl7X8,566
|
|
15
|
+
nexom/assets/server/templates/base.html,sha256=RVW_63gA1sr7pqNkfB6Djk5an_VFpowahDIHGjfV-Wk,349
|
|
16
|
+
nexom/assets/server/templates/default.html,sha256=EKG9NTYkXngdCiDodSI1Kuic_ZwVwdeRc3VLq6fX5UI,167
|
|
17
|
+
nexom/assets/server/templates/document.html,sha256=16ClimpeqhLnXFNa8nMdMOlXUu8JOw7XxfpjU9DdIFs,6243
|
|
18
|
+
nexom/assets/server/templates/footer.html,sha256=1NZbbarU-CQhs1OPs2MTzhnWu0h7YYiEKDIP_cgIl9I,98
|
|
19
|
+
nexom/assets/server/templates/header.html,sha256=VgkCtCVE1J-eGEYvbBgWSUU-QauEf6xuvweOE-84U9c,75
|
|
20
|
+
nexom/buildTools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
|
+
nexom/buildTools/build.py,sha256=q4_4seJSH8fmRruDb1LkKAaQTBDtBKqInIJk46i_LMg,3317
|
|
22
|
+
nexom/core/__init__.py,sha256=EsfVI7jSjLWUhwMIWasUDIOdlSHtOsFSJ6WfzkrtY5o,19
|
|
23
|
+
nexom/core/error.py,sha256=YXMYQ-rgMXpId_d7_uxRVNFm-YMu99LjQBImTSTftTY,4148
|
|
24
|
+
nexom/engine/__init__.py,sha256=yorquMUk_CF949j-Tw2hkavz5VpbeQhAQ1pYZbMLIcw,32
|
|
25
|
+
nexom/engine/object_html_render.py,sha256=-99gxYv2m2emv7JvTVuKJCx9V8UpKRpFjmx8Qw5e_8A,6928
|
|
26
|
+
nexom/web/__init__.py,sha256=5Ox2txlSe4M4y353Xi7PymC_bCsFtgP0tjEI6wQfai8,107
|
|
27
|
+
nexom/web/cookie.py,sha256=Ad7TamzkUOGR7VMq4LTSAKATS43ycP7o6KRKOSLhyu4,1940
|
|
28
|
+
nexom/web/http_status_codes.py,sha256=R4ka3n4rijqvfahF5n5kS-Qrg8bZSsrvF8lGnpKWAgY,1934
|
|
29
|
+
nexom/web/middleware.py,sha256=7bHGtEem92QhgULOvTFDFlZ4K719CQgu9RKj1g7XOW8,1429
|
|
30
|
+
nexom/web/path.py,sha256=VcNhPOpVURn5G26iNgI_qU30RnpxUSXceYGLj-yASwA,4299
|
|
31
|
+
nexom/web/request.py,sha256=jNYdEbYCOKmgm_2iPVmB_IwCSCyLWgODBIl1974hSVY,1680
|
|
32
|
+
nexom/web/response.py,sha256=Z94-qXq2mlzhY1QkHPTTNlewac79gBOoV0ClP3h-YRE,3854
|
|
33
|
+
nexom/web/template.py,sha256=qPH0bGSzwn8tNIsPdxVoFZDL5NSO2Yxd6gPXShL2mXg,3589
|
|
34
|
+
nexom-0.1.3.dist-info/licenses/LICENSE,sha256=YbcHyxYLJ5jePeMS_NXpR9yiZjP5skhn32LvcKeknJw,1066
|
|
35
|
+
nexom-0.1.3.dist-info/METADATA,sha256=fX40TNjFNKHmp4wupKEAnKdCrV4ZTQiCBjjhf8bL7tc,5406
|
|
36
|
+
nexom-0.1.3.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
37
|
+
nexom-0.1.3.dist-info/entry_points.txt,sha256=0r1egKZmF1MUo25AKPt-2d55sk5Q_EIBOQwD3JC8RgI,46
|
|
38
|
+
nexom-0.1.3.dist-info/top_level.txt,sha256=mTyUruscL3rqXvYJRo8KGwDM6PWXRzgf4CamLr8LSX4,6
|
|
39
|
+
nexom-0.1.3.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TouriAida
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nexom
|