Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove middleware for cookies #90

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions backend/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import os
from pathlib import Path

from fastapi import FastAPI, Request, Response
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from langserve import add_routes
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from starlette.responses import Response
import uuid

from server.api import configurables, examples, extract, extractors, shared, suggest
from server.extraction_runnable import (
Expand All @@ -33,24 +30,6 @@
)


class EnsureUserIDMiddleware(BaseHTTPMiddleware):
async def dispatch(
self, request: Request, call_next: RequestResponseEndpoint
) -> Response:
user_id = request.cookies.get("user_id")
if not user_id:
user_id = str(uuid.uuid4()) # Generate a new user_id
request.state.user_id = user_id # Set user_id in request state
response = await call_next(request)
response.set_cookie(key="user_id", value=user_id, httponly=True)
else:
request.state.user_id = user_id # Set existing user_id in request state
response = await call_next(request)
return response


app.add_middleware(EnsureUserIDMiddleware)

ROOT = Path(__file__).parent.parent

ORIGINS = os.environ.get("CORS_ORIGINS", "").split(",")
Expand Down
Loading