Self-heal missing data/links.json instead of crashing
Production 500'd on every request because the ./data volume mount was an empty host directory, shadowing the seed file baked into the image. load_data() now creates a minimal default file on first run if none exists, so an empty/fresh data volume no longer takes the site down. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c3df325da7
commit
ada56f846b
1 file changed
+15
@@ -17,8 +17,23 @@ DATA_FILE = Path(os.environ.get("DATA_FILE", "data/links.json"))
|
||||
|
||||
COLORS = ["blue", "green", "orange", "pink"]
|
||||
|
||||
DEFAULT_DATA = {
|
||||
"index": {
|
||||
"title": "My Links",
|
||||
"subtitle": "",
|
||||
"subtitle2": "",
|
||||
"footer_label": "",
|
||||
"footer_href": "",
|
||||
"sections": [],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def load_data():
|
||||
if not DATA_FILE.exists():
|
||||
DATA_FILE.parent.mkdir(parents=True, exist_ok=True)
|
||||
save_data(DEFAULT_DATA)
|
||||
return json.loads(json.dumps(DEFAULT_DATA))
|
||||
with open(DATA_FILE, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
Reference in new issue
Block a user