fix render issue

This commit is contained in:
h z
2024-12-03 16:36:32 +00:00
parent 23b9db19a8
commit dc8ee49c9e
3 changed files with 9 additions and 14 deletions

17
app.py
View File

@@ -18,22 +18,17 @@ db_handler.setFormatter(formatter)
logger.addHandler(db_handler)
logger.setLevel(logging.INFO)
def is_allowed_origin(origin):
parsed_origin = urlparse(origin)
if parsed_origin.hostname in ['localhost', '127.0.0.1']:
return True
allowed_origins = [
"https://login.hangman-lab.top",
"https://git.hangman-lab.top",
]
return origin in allowed_origins
try:
db.create_all()
except Exception as e:
print("db not ready")
print(f"db not ready {e}")
app = Flask(__name__)
app.secret_key = env_provider.SESSION_SECRET_KEY
CORS(app, resources={r"/api/*": {"origins": is_allowed_origin}})
CORS(app, resources={r"/api/*": {"origins": [
"https://login.hangman-lab.top",
"https://git.hangman-lab.top",
"http://127.0.0.1:3000"
]}})
limiter.init_app(app)

View File

@@ -1,10 +1,10 @@
#db/models/Resource.py
from sqlalchemy import Column, Text, LargeBinary
from sqlalchemy import Column, Text, LargeBinary, String
from db.models import Base
class Resource(Base):
__tablename__ = 'resources'
id = Column(Text, primary_key=True)
id = Column(String(255), primary_key=True)
content = Column(LargeBinary, nullable=False)
data_type = Column(Text, nullable=False)

View File

@@ -12,8 +12,8 @@ class DatabaseLogHandler(logging.Handler):
message = self.format(record)
level = record.levelname
extra = str(getattr(record, 'extra', None)) if hasattr(record, 'extra') else None
log_entry = Log(message=message, level=level, application=self.application, extra=extra)
print(message)
try:
with get_db() as db:
db.add(log_entry)