can anyone help me to setup the quick start with f...
# support-questions-legacy
v
can anyone help me to setup the quick start with fastapi? im using self hosted with docker, i already try the docs and kinda work, but there's no routes, its like i dont do it here is my code:
Copy code
python
import uvicorn
 
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

# Core Application Instance
app = FastAPI(
    title='Oasys Pipeliner',
    version='v1.0.0',
)

from supertokens_python import init as supertokens_init
from supertokens_python import InputAppInfo, SupertokensConfig
from supertokens_python.recipe import emailpassword, session
from supertokens_python.framework.fastapi import get_middleware
from supertokens_python import get_all_cors_headers

from supertokens_python.recipe import userroles

supertokens_init(
    app_info=InputAppInfo(
        app_name="oasys",
        api_domain="http://localhost:8000",
        website_domain="http://localhost:8000",
        api_base_path="/auth",
        website_base_path="/auth"
    ),
    supertokens_config=SupertokensConfig(
        # try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
        connection_uri="http://localhost:3567",
        # api_key="IF YOU HAVE AN API KEY FOR THE CORE, ADD IT HERE"
    ),
    framework='fastapi',
    recipe_list=[
        session.init(), # initializes session features
        emailpassword.init()
    ],
    mode='wsgi' # use wsgi if you are running using gunicorn
)

app.add_middleware(
    CORSMiddleware,
    allow_origins=[
        "http://localhost:8000"
    ],
    allow_credentials=True,
    allow_methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
    allow_headers=["Content-Type"] + get_all_cors_headers(),
)

if __name__ == "__main__":
   uvicorn.run("main:app")
r
Hey @Vrl
Also, we add the necessary routes dynamically via a middleware
v
hello rp, im already try this example, maybe i've been done something wrong in the process...
but from this example, i copy paste it into a new file for test, change the host to my local docker and change the recipe list to just email and password methods
but im still dont have access to the routes
r
@KShivendu can help here
v
i have a few questions
k
hey @Vrl we don't specifically add anything to the openapi spec auto generated by fastapi. But the requests should be working as expected.
sure go ahead.
v
first, if im done correctly, the routs will show at /docs?
oh ok
second, i need to setup my front or can i use postman for test?
k
you can go for either 😄
although, our frontend sdk will make it easy to do the requests. directly using postman would mean some manual work.
v
hmm ok
so, if i done correctly what should i get when i make an empty request to /auth/signin
currently im getting 404
Copy code
C:\Users\PTI>curl http://localhost:8000/auth/signin
{"detail":"Not Found"}
k
fetch("http://localhost:8000/auth/session/refresh", {method: "POST"}).then(res => res.text()).then(console.log)
try this in browser
this should be a post request.
v
i got cors blocked
k
@Vrl you can refer our SDK API docs which follows OpenAPI https://app.swaggerhub.com/apis/supertokens/FDI
open with the same url in browser. localhost://8000
v
im getting some errors, but it seens to work, maybe i've been make requests to the wrong route method
k
what errors
v
in cors im already set my localhost and still got error, but in curl i can see a propely error from invalid parameters
but i can handle for that now
thank you for the help
k
good to know. you're welcome. feel free to message if anything else comes up 😄
v
ok ty
8 Views