Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
eyurtsev committed Mar 22, 2024
1 parent de40657 commit 0b29f9a
Showing 1 changed file with 1 addition and 22 deletions.
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

0 comments on commit 0b29f9a

Please sign in to comment.