aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat_scholar/web.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-09-15 17:40:13 -0700
committerBryan Newbold <bnewbold@archive.org>2020-09-15 17:40:15 -0700
commit7b80bfe54783bd662d0e71b3eee09c5ecf304355 (patch)
tree92277f982452fe34b7f1c7de2cbad2b3050004b9 /fatcat_scholar/web.py
parent0ec7f4a0fc8da9d37ad8afe60da070aaded8d5f2 (diff)
downloadfatcat-scholar-7b80bfe54783bd662d0e71b3eee09c5ecf304355.tar.gz
fatcat-scholar-7b80bfe54783bd662d0e71b3eee09c5ecf304355.zip
web robots.txt
Two variants depending on environment.
Diffstat (limited to 'fatcat_scholar/web.py')
-rw-r--r--fatcat_scholar/web.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py
index 866214e..5ad301d 100644
--- a/fatcat_scholar/web.py
+++ b/fatcat_scholar/web.py
@@ -7,6 +7,7 @@ So far there are few endpoints, so we just put them all here!
import babel.support
from fastapi import FastAPI, APIRouter, Request, Depends, Response
from fastapi.staticfiles import StaticFiles
+from fastapi.responses import PlainTextResponse
from dynaconf import settings
from typing import Optional, Any
@@ -218,3 +219,15 @@ for lang_option in I18N_LANG_OPTIONS:
app.include_router(api)
app.mount("/static", StaticFiles(directory="fatcat_scholar/static"), name="static")
+
+ROBOTS_ALLOW = open("fatcat_scholar/static/robots.allow.txt", "r").read()
+ROBOTS_DISALLOW = open("fatcat_scholar/static/robots.disallow.txt", "r").read()
+
+
+@app.get("/robots.txt", include_in_schema=False)
+async def robots_txt(response_class=PlainTextResponse) -> Any:
+ print(ROBOTS_ALLOW)
+ if settings.SCHOLAR_ENV == "prod":
+ return PlainTextResponse(ROBOTS_ALLOW)
+ else:
+ return PlainTextResponse(ROBOTS_DISALLOW)