Initial commit: Key Ajans portfolio site
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import os
|
||||
|
||||
from flask import Flask, render_template, session
|
||||
|
||||
import db
|
||||
import security
|
||||
from auth_routes import auth_bp
|
||||
from project_routes import project_bp, public_projects
|
||||
from request_routes import request_bp
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
cfg = security.load_server_config()
|
||||
|
||||
app.config.update(
|
||||
SECRET_KEY=cfg["secret"],
|
||||
SESSION_COOKIE_HTTPONLY=True,
|
||||
SESSION_COOKIE_SAMESITE="Lax",
|
||||
# Üretimde HTTPS altında bu değeri True yapın:
|
||||
SESSION_COOKIE_SECURE=False,
|
||||
PERMANENT_SESSION_LIFETIME=86400,
|
||||
MAX_CONTENT_LENGTH=60 * 1024 * 1024,
|
||||
)
|
||||
|
||||
db.init_db()
|
||||
app.teardown_appcontext(db.close_db)
|
||||
app.before_request(security.before_request)
|
||||
app.after_request(security.after_request)
|
||||
|
||||
@app.context_processor
|
||||
def inject_globals():
|
||||
return {
|
||||
"csrf_token": security.ensure_csrf_token(),
|
||||
"is_admin": session.get("role") == "admin",
|
||||
"current_user": session.get("name"),
|
||||
}
|
||||
|
||||
@app.errorhandler(400)
|
||||
def bad_request(e):
|
||||
return render_template("error.html", code=400, message="Geçersiz istek."), 400
|
||||
|
||||
@app.errorhandler(403)
|
||||
def forbidden(e):
|
||||
return render_template("error.html", code=403, message="Bu sayfaya erişim yetkiniz yok."), 403
|
||||
|
||||
@app.errorhandler(404)
|
||||
def not_found(e):
|
||||
return render_template("error.html", code=404, message="Sayfa bulunamadı."), 404
|
||||
|
||||
@app.errorhandler(429)
|
||||
def too_many(e):
|
||||
return render_template("error.html", code=429, message="Çok fazla istek. Lütfen biraz bekleyin."), 429
|
||||
|
||||
@app.errorhandler(500)
|
||||
def server_error(e):
|
||||
return render_template("error.html", code=500, message="Beklenmeyen bir hata oluştu."), 500
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return render_template("index.html", projects=public_projects())
|
||||
|
||||
app.register_blueprint(auth_bp)
|
||||
app.register_blueprint(project_bp)
|
||||
app.register_blueprint(request_bp)
|
||||
return app
|
||||
|
||||
|
||||
app = create_app()
|
||||
|
||||
if __name__ == "__main__":
|
||||
port = int(os.environ.get("PORT", 3000))
|
||||
app.run(host="0.0.0.0", port=port, threaded=True)
|
||||
Reference in New Issue
Block a user