[mod] separate index and search routes

This makes it easier to separately handle search and index requests
from a web server or from a reverse proxy.

If a request to index contains a query, a permanent redirect HTTP response
is returned. This should give some level of backwards compatibility
for users that have set a searx instance in their browser's search bar.
This commit is contained in:
Marc Abonce Seguin 2019-07-29 21:25:05 -07:00
parent 45f58a4a2a
commit 8d71420b45
17 changed files with 70 additions and 42 deletions

View file

@ -531,10 +531,22 @@ def index_error(output_format, error_message):
)
@app.route('/search', methods=['GET', 'POST'])
@app.route('/', methods=['GET', 'POST'])
def index():
"""Render index page.
"""Render index page."""
# redirect to search if there's a query in the request
if request.form.get('q'):
return redirect(url_for('search'), 308)
return render(
'index.html',
)
@app.route('/search', methods=['GET', 'POST'])
def search():
"""Search query in q and return results.
Supported outputs: html, json, csv, rss.
"""