mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-15 20:57:56 +08:00
do in-app compression only for CLI (#1285)
This commit is contained in:
@@ -4,8 +4,6 @@ import logging
|
||||
|
||||
from flask import Flask, redirect, current_app, make_response, render_template, abort
|
||||
from flask import Blueprint, request, send_from_directory
|
||||
from flask_caching import Cache
|
||||
from flask_compress import Compress
|
||||
from flask_cors import CORS
|
||||
from flask_restful import Api, Resource
|
||||
|
||||
@@ -208,10 +206,6 @@ class Server:
|
||||
self.app = Flask(__name__, static_folder="../common/web/static")
|
||||
self.app.json_encoder = Float32JSONEncoder
|
||||
|
||||
self.cache = Cache(config={"CACHE_TYPE": "simple", "CACHE_DEFAULT_TIMEOUT": 860_000})
|
||||
self.cache.init_app(self.app)
|
||||
|
||||
Compress(self.app)
|
||||
CORS(self.app, supports_credentials=True)
|
||||
|
||||
# enable session data
|
||||
|
||||
@@ -6,12 +6,14 @@ import sys
|
||||
import webbrowser
|
||||
|
||||
import click
|
||||
from flask_compress import Compress
|
||||
|
||||
from server.common.utils import sort_options
|
||||
from server.common.errors import DatasetAccessError, ConfigurationError
|
||||
from server.data_common.matrix_loader import MatrixDataCacheManager
|
||||
from server.common.app_config import AppConfig
|
||||
from server.common.default_config import default_config
|
||||
from server.app.app import Server
|
||||
|
||||
DEFAULT_CONFIG = AppConfig()
|
||||
|
||||
@@ -268,6 +270,24 @@ def handle_scripts(scripts):
|
||||
click.confirm(f"Are you sure you want to inject these scripts: {scripts_pretty}?", abort=True)
|
||||
|
||||
|
||||
class CliLaunchServer(Server):
|
||||
"""
|
||||
the CLI runs a local web server, and needs to enable a few more features.
|
||||
"""
|
||||
def __init__(self, matrix_data_cache_manager, annotations, app_config):
|
||||
super().__init__(matrix_data_cache_manager, annotations, app_config)
|
||||
self.app.config["COMPRESS_MIMETYPES"] = [
|
||||
"text/html",
|
||||
"text/css",
|
||||
"text/xml",
|
||||
"application/json",
|
||||
"application/javascript",
|
||||
"application/octet-stream",
|
||||
]
|
||||
compress = Compress(self.app)
|
||||
compress.init_app(self.app)
|
||||
|
||||
|
||||
@sort_options
|
||||
@click.command(
|
||||
short_help="Launch the cellxgene data viewer. " "Run `cellxgene launch --help` for more information.",
|
||||
@@ -377,9 +397,7 @@ def launch(
|
||||
user_annotations = app_config.user_annotations
|
||||
|
||||
# create the server
|
||||
from server.app.app import Server
|
||||
|
||||
server = Server(matrix_data_cache_manager, user_annotations, app_config)
|
||||
server = CliLaunchServer(matrix_data_cache_manager, user_annotations, app_config)
|
||||
|
||||
if not app_config.server__verbose:
|
||||
log = logging.getLogger("werkzeug")
|
||||
|
||||
@@ -2,7 +2,6 @@ anndata>=0.6.20
|
||||
click>=6.7
|
||||
fastobo>=0.6.1
|
||||
Flask>=1.0.2
|
||||
Flask-Caching>=1.4.0
|
||||
Flask-Compress>=1.4.0
|
||||
Flask-Cors>=3.0.6
|
||||
Flask-RESTful>=0.3.6
|
||||
|
||||
Reference in New Issue
Block a user