Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add robots.txt #607

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cubedash/_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@

_DEFAULT_ARRIVALS_DAYS: int = app.config.get("CUBEDASH_DEFAULT_ARRIVALS_DAY_COUNT", 14)

_ROBOTS_TXT_DEFAULT = (
"User-Agent: *\nAllow: /\nDisallow: /products/*/*\nDisallow: /stac/**"
)

# Add server timings to http headers.
if app.config.get("CUBEDASH_SHOW_PERF_TIMES", False):
_monitoring.init_app_monitoring()
Expand Down Expand Up @@ -674,6 +678,13 @@ def about_page():
)


@app.route("/robots.txt")
def robots_txt():
return utils.as_json(
flask.current_app.config.get("ROBOTS_TXT", _ROBOTS_TXT_DEFAULT)
)


@app.route("/")
def default_redirect():
"""Redirect to default starting page."""
Expand Down
8 changes: 8 additions & 0 deletions integration_tests/test_page_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,14 @@ def check_doc_start_has_hint(hint: str, url: str):
)


def test_get_robots(client: FlaskClient):
"""
Check that robots.txt is correctly served from root
"""
text, rv = get_text_response(client, "/robots.txt")
assert "User-Agent: *" in text


def test_all_give_404s(client: FlaskClient):
"""
We should get 404 messages, not exceptions, for missing things.
Expand Down
Loading