from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse from fastapi import FastAPI import json app = FastAPI() app.add_middleware(CORSMiddleware, allow_origins = ['*'], allow_credentials = True, allow_methods = ['*'], allow_headers = ['*']) @app.get('/') def index(): return JSONResponse(status_code = 200, content = {'status' : 'online'}) @app.get('/read') def read_route(): with open('cookies.json', 'r', encoding = 'utf-8') as file: data = json.load(file) return JSONResponse(status_code = 200, content = data) @app.get('/write/{number}') def read_route(number: int): with open('cookies.json', 'r', encoding = 'utf-8') as file: data = json.load(file) data['deneme'] = number with open('cookies.json', 'w', encoding = 'utf-8') as file: json.dump(data, file, ensure_ascii = False, indent = 4) return JSONResponse(status_code = 200, content = 'ok')