mirror of
https://github.com/searxng/searxng.git
synced 2026-08-07 15:51:26 +00:00
Compare commits
2 Commits
5cbf422621
...
f7c8e4c353
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7c8e4c353 | ||
|
|
42f102ce1b |
@@ -19,3 +19,4 @@ tomli==2.2.1; python_version < '3.11'
|
|||||||
msgspec==0.19.0
|
msgspec==0.19.0
|
||||||
typer-slim==0.16.0
|
typer-slim==0.16.0
|
||||||
isodate==0.7.2
|
isodate==0.7.2
|
||||||
|
whitenoise==6.9.0
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
# pylint: disable=,missing-module-docstring,missing-class-docstring
|
# pylint: disable=,missing-module-docstring,missing-class-docstring
|
||||||
|
|
||||||
|
import importlib
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
|
||||||
import importlib
|
|
||||||
|
|
||||||
# fallback values
|
# fallback values
|
||||||
# if there is searx.version_frozen module, and it is not possible to get the git tag
|
# if there is searx.version_frozen module, and it is not possible to get the git tag
|
||||||
VERSION_STRING = "1.0.0"
|
VERSION_STRING = "1.0.0"
|
||||||
VERSION_TAG = "1.0.0"
|
VERSION_TAG = "1.0.0"
|
||||||
GIT_URL = "unknow"
|
DOCKER_TAG = "1.0.0"
|
||||||
GIT_BRANCH = "unknow"
|
GIT_URL = "unknown"
|
||||||
|
GIT_BRANCH = "unknown"
|
||||||
|
|
||||||
logger = logging.getLogger("searx")
|
logger = logging.getLogger("searx")
|
||||||
|
|
||||||
@@ -83,6 +84,25 @@ def get_git_version():
|
|||||||
return git_version, tag_version, docker_tag
|
return git_version, tag_version, docker_tag
|
||||||
|
|
||||||
|
|
||||||
|
def get_information():
|
||||||
|
version_string = VERSION_STRING
|
||||||
|
version_tag = VERSION_TAG
|
||||||
|
docker_tag = DOCKER_TAG
|
||||||
|
git_url = GIT_URL
|
||||||
|
git_branch = GIT_BRANCH
|
||||||
|
|
||||||
|
try:
|
||||||
|
version_string, version_tag, docker_tag = get_git_version()
|
||||||
|
except subprocess.CalledProcessError as ex:
|
||||||
|
logger.error("Error while getting the version: %s", ex.stderr)
|
||||||
|
try:
|
||||||
|
git_url, git_branch = get_git_url_and_branch()
|
||||||
|
except subprocess.CalledProcessError as ex:
|
||||||
|
logger.error("Error while getting the git URL & branch: %s", ex.stderr)
|
||||||
|
|
||||||
|
return version_string, version_tag, docker_tag, git_url, git_branch
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vf = importlib.import_module('searx.version_frozen')
|
vf = importlib.import_module('searx.version_frozen')
|
||||||
VERSION_STRING, VERSION_TAG, DOCKER_TAG, GIT_URL, GIT_BRANCH = (
|
VERSION_STRING, VERSION_TAG, DOCKER_TAG, GIT_URL, GIT_BRANCH = (
|
||||||
@@ -93,18 +113,7 @@ try:
|
|||||||
vf.GIT_BRANCH,
|
vf.GIT_BRANCH,
|
||||||
)
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
VERSION_STRING, VERSION_TAG, DOCKER_TAG, GIT_URL, GIT_BRANCH = get_information()
|
||||||
try:
|
|
||||||
VERSION_STRING, VERSION_TAG, DOCKER_TAG = get_git_version()
|
|
||||||
except subprocess.CalledProcessError as ex:
|
|
||||||
logger.error("Error while getting the version: %s", ex.stderr)
|
|
||||||
try:
|
|
||||||
GIT_URL, GIT_BRANCH = get_git_url_and_branch()
|
|
||||||
except subprocess.CalledProcessError as ex:
|
|
||||||
logger.error("Error while getting the git URL & branch: %s", ex.stderr)
|
|
||||||
except FileNotFoundError as ex:
|
|
||||||
logger.error("%s is not found, fallback to the default version", ex.filename)
|
|
||||||
|
|
||||||
|
|
||||||
logger.info("version: %s", VERSION_STRING)
|
logger.info("version: %s", VERSION_STRING)
|
||||||
|
|
||||||
@@ -112,6 +121,8 @@ if __name__ == "__main__":
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
if len(sys.argv) >= 2 and sys.argv[1] == "freeze":
|
if len(sys.argv) >= 2 and sys.argv[1] == "freeze":
|
||||||
|
VERSION_STRING, VERSION_TAG, DOCKER_TAG, GIT_URL, GIT_BRANCH = get_information()
|
||||||
|
|
||||||
# freeze the version (to create an archive outside a git repository)
|
# freeze the version (to create an archive outside a git repository)
|
||||||
python_code = f"""# SPDX-License-Identifier: AGPL-3.0-or-later
|
python_code = f"""# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
# pylint: disable=missing-module-docstring
|
# pylint: disable=missing-module-docstring
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ from pygments.formatters import HtmlFormatter # pylint: disable=no-name-in-modu
|
|||||||
|
|
||||||
from werkzeug.serving import is_running_from_reloader
|
from werkzeug.serving import is_running_from_reloader
|
||||||
|
|
||||||
|
from whitenoise import WhiteNoise
|
||||||
|
from whitenoise.base import Headers
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
@@ -147,7 +150,7 @@ STATS_SORT_PARAMETERS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Flask app
|
# Flask app
|
||||||
app = Flask(__name__, static_folder=settings['ui']['static_path'], template_folder=templates_path)
|
app = Flask(__name__, static_folder=None, template_folder=templates_path)
|
||||||
|
|
||||||
app.jinja_env.trim_blocks = True
|
app.jinja_env.trim_blocks = True
|
||||||
app.jinja_env.lstrip_blocks = True
|
app.jinja_env.lstrip_blocks = True
|
||||||
@@ -245,6 +248,7 @@ def custom_url_for(endpoint: str, **values):
|
|||||||
if not _STATIC_FILES:
|
if not _STATIC_FILES:
|
||||||
_STATIC_FILES = webutils.get_static_file_list()
|
_STATIC_FILES = webutils.get_static_file_list()
|
||||||
|
|
||||||
|
# handled by WhiteNoise
|
||||||
if endpoint == "static" and values.get("filename"):
|
if endpoint == "static" and values.get("filename"):
|
||||||
|
|
||||||
# We need to verify the "filename" argument: in the jinja templates
|
# We need to verify the "filename" argument: in the jinja templates
|
||||||
@@ -257,9 +261,11 @@ def custom_url_for(endpoint: str, **values):
|
|||||||
if arg_filename not in _STATIC_FILES:
|
if arg_filename not in _STATIC_FILES:
|
||||||
# try file in the current theme
|
# try file in the current theme
|
||||||
theme_name = sxng_request.preferences.get_value("theme")
|
theme_name = sxng_request.preferences.get_value("theme")
|
||||||
arg_filename = f"themes/{theme_name}/{arg_filename}"
|
theme_filename = f"themes/{theme_name}/{arg_filename}"
|
||||||
if arg_filename in _STATIC_FILES:
|
if theme_filename in _STATIC_FILES:
|
||||||
values["filename"] = arg_filename
|
values["filename"] = theme_filename
|
||||||
|
|
||||||
|
return f"/static/{values['filename']}"
|
||||||
|
|
||||||
if endpoint == "info" and "locale" not in values:
|
if endpoint == "info" and "locale" not in values:
|
||||||
|
|
||||||
@@ -1424,7 +1430,22 @@ def init():
|
|||||||
favicons.init()
|
favicons.init()
|
||||||
|
|
||||||
|
|
||||||
application = app
|
def static_headers(headers: Headers, _path: str, _url: str) -> None:
|
||||||
|
headers['Cache-Control'] = 'public, max-age=30, stale-while-revalidate=60'
|
||||||
|
|
||||||
|
for header, value in settings['server']['default_http_headers'].items():
|
||||||
|
headers[header] = value
|
||||||
|
|
||||||
|
|
||||||
|
app.wsgi_app = WhiteNoise(
|
||||||
|
app.wsgi_app,
|
||||||
|
root=settings['ui']['static_path'],
|
||||||
|
prefix="static",
|
||||||
|
max_age=None,
|
||||||
|
allow_all_origins=False,
|
||||||
|
add_headers_function=static_headers,
|
||||||
|
)
|
||||||
|
|
||||||
patch_application(app)
|
patch_application(app)
|
||||||
init()
|
init()
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,4 @@ pythonpath = ${SEARXNG_SRC}
|
|||||||
http = ${SEARXNG_INTERNAL_HTTP}
|
http = ${SEARXNG_INTERNAL_HTTP}
|
||||||
buffer-size = 8192
|
buffer-size = 8192
|
||||||
|
|
||||||
# To serve the static files via the WSGI server
|
|
||||||
static-map = /static=${SEARXNG_STATIC}
|
|
||||||
static-gzip-all = True
|
|
||||||
offload-threads = %k
|
offload-threads = %k
|
||||||
|
|||||||
@@ -72,7 +72,4 @@ pythonpath = ${SEARXNG_SRC}
|
|||||||
socket = ${SEARXNG_UWSGI_SOCKET}
|
socket = ${SEARXNG_UWSGI_SOCKET}
|
||||||
buffer-size = 8192
|
buffer-size = 8192
|
||||||
|
|
||||||
# To serve the static files via the WSGI server
|
|
||||||
static-map = /static=${SEARXNG_STATIC}
|
|
||||||
static-gzip-all = True
|
|
||||||
offload-threads = %k
|
offload-threads = %k
|
||||||
|
|||||||
@@ -78,7 +78,4 @@ pythonpath = ${SEARXNG_SRC}
|
|||||||
http = ${SEARXNG_INTERNAL_HTTP}
|
http = ${SEARXNG_INTERNAL_HTTP}
|
||||||
buffer-size = 8192
|
buffer-size = 8192
|
||||||
|
|
||||||
# To serve the static files via the WSGI server
|
|
||||||
static-map = /static=${SEARXNG_STATIC}
|
|
||||||
static-gzip-all = True
|
|
||||||
offload-threads = %k
|
offload-threads = %k
|
||||||
|
|||||||
@@ -75,7 +75,4 @@ pythonpath = ${SEARXNG_SRC}
|
|||||||
socket = ${SEARXNG_UWSGI_SOCKET}
|
socket = ${SEARXNG_UWSGI_SOCKET}
|
||||||
buffer-size = 8192
|
buffer-size = 8192
|
||||||
|
|
||||||
# To serve the static files via the WSGI server
|
|
||||||
static-map = /static=${SEARXNG_STATIC}
|
|
||||||
static-gzip-all = True
|
|
||||||
offload-threads = %k
|
offload-threads = %k
|
||||||
|
|||||||
Reference in New Issue
Block a user