Skip to content

Commit 63886a3

Browse files
committed
Serve site with Flask on Vercel
1 parent 67334c3 commit 63886a3

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

site/app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pathlib import Path
2+
3+
from flask import Flask, abort, send_from_directory
4+
5+
6+
BASE_DIR = Path(__file__).resolve().parent
7+
8+
app = Flask(__name__, static_folder=None)
9+
10+
11+
@app.get("/")
12+
def index():
13+
return send_from_directory(BASE_DIR, "index.html")
14+
15+
16+
@app.get("/<path:path>")
17+
def serve_site_file(path):
18+
target = (BASE_DIR / path).resolve()
19+
if not target.is_file() or BASE_DIR not in target.parents:
20+
abort(404)
21+
return send_from_directory(BASE_DIR, path)
22+

site/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Flask==3.0.3

site/vercel.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
{
2-
"buildCommand": null,
3-
"outputDirectory": "."
1+
{
2+
"version": 2,
3+
"builds": [
4+
{
5+
"src": "app.py",
6+
"use": "@vercel/python"
7+
}
8+
],
9+
"routes": [
10+
{
11+
"src": "/(.*)",
12+
"dest": "app.py"
13+
}
14+
]
415
}

0 commit comments

Comments
 (0)