fix: test vercel
This commit is contained in:
parent
5c3a98628c
commit
9078c6c940
|
@ -1,61 +1,45 @@
|
||||||
# from fastapi import FastAPI
|
|
||||||
# from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel, SecurityScheme
|
|
||||||
# from fastapi.openapi.utils import get_openapi
|
|
||||||
# from fastapi.security import OAuth2PasswordBearer
|
|
||||||
# from routes.index import api_router
|
|
||||||
# from fastapi.middleware.cors import CORSMiddleware
|
|
||||||
|
|
||||||
# app = FastAPI()
|
|
||||||
|
|
||||||
# # Konfigurasi Swagger agar hanya meminta token (tanpa login ulang)
|
|
||||||
# def custom_openapi():
|
|
||||||
# if app.openapi_schema:
|
|
||||||
# return app.openapi_schema
|
|
||||||
# openapi_schema = get_openapi(
|
|
||||||
# title="API Prediction",
|
|
||||||
# version="1.0.0",
|
|
||||||
# description="API for Tomato Price Prediction",
|
|
||||||
# routes=app.routes,
|
|
||||||
# )
|
|
||||||
# openapi_schema["components"]["securitySchemes"] = {
|
|
||||||
# "BearerAuth": {
|
|
||||||
# "type": "http",
|
|
||||||
# "scheme": "bearer",
|
|
||||||
# "bearerFormat": "JWT",
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# for path in openapi_schema["paths"].values():
|
|
||||||
# for method in path.values():
|
|
||||||
# method["security"] = [{"BearerAuth": []}]
|
|
||||||
# app.openapi_schema = openapi_schema
|
|
||||||
# return app.openapi_schema
|
|
||||||
|
|
||||||
# app.openapi = custom_openapi # Pakai custom OpenAPI
|
|
||||||
|
|
||||||
# app.include_router(api_router)
|
|
||||||
|
|
||||||
|
|
||||||
# # Middleware untuk CORS (Opsional, jika API digunakan oleh frontend)
|
|
||||||
# app.add_middleware(
|
|
||||||
# CORSMiddleware,
|
|
||||||
# allow_origins=["http://localhost:5173"], # Ganti dengan domain frontend jika perlu
|
|
||||||
# allow_credentials=False,
|
|
||||||
# allow_methods=["*"],
|
|
||||||
# allow_headers=["*"],
|
|
||||||
# )
|
|
||||||
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel, SecurityScheme
|
||||||
|
from fastapi.openapi.utils import get_openapi
|
||||||
|
from fastapi.security import OAuth2PasswordBearer
|
||||||
|
from routes.index import api_router
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
@app.get("/")
|
# Konfigurasi Swagger agar hanya meminta token (tanpa login ulang)
|
||||||
async def read_root():
|
def custom_openapi():
|
||||||
return {"Hello": "World"}
|
if app.openapi_schema:
|
||||||
|
return app.openapi_schema
|
||||||
|
openapi_schema = get_openapi(
|
||||||
|
title="API Prediction",
|
||||||
|
version="1.0.0",
|
||||||
|
description="API for Tomato Price Prediction",
|
||||||
|
routes=app.routes,
|
||||||
|
)
|
||||||
|
openapi_schema["components"]["securitySchemes"] = {
|
||||||
|
"BearerAuth": {
|
||||||
|
"type": "http",
|
||||||
|
"scheme": "bearer",
|
||||||
|
"bearerFormat": "JWT",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for path in openapi_schema["paths"].values():
|
||||||
|
for method in path.values():
|
||||||
|
method["security"] = [{"BearerAuth": []}]
|
||||||
|
app.openapi_schema = openapi_schema
|
||||||
|
return app.openapi_schema
|
||||||
|
|
||||||
@app.get("/api/ping")
|
app.openapi = custom_openapi # Pakai custom OpenAPI
|
||||||
async def ping():
|
|
||||||
return {"ping": "pong"}
|
|
||||||
|
|
||||||
# Penting untuk Vercel
|
app.include_router(api_router)
|
||||||
handler = app
|
|
||||||
|
|
||||||
|
# Middleware untuk CORS (Opsional, jika API digunakan oleh frontend)
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=["http://localhost:5173"], # Ganti dengan domain frontend jika perlu
|
||||||
|
allow_credentials=False,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue