Can someone spot what's going wrong here? I had Su...
# support-questions-legacy
h
Can someone spot what's going wrong here? I had SuperTokens working before but I'm now trying to introduce nginx and it's causing a mess. By default, request URI's are assumed to be refering to static files from my React production build. However, requests to
/api/*
are forwarded to my Python Flask API, which is where the backend SuperTokens SDK is implemented. As mentioned, it worked just before switching to nginx but now all requests to
localhost:80/api/auth
and direct ones to the api
localhost:8080/auth
all return the
404
from this function:
Copy code
@app.route('/', defaults={'u_path': ''})
@app.route('/<path:u_path>')
def catch_all(u_path: str):
    abort(404)
I am able to reach other API endpoints just fine through for example
http://localhost/api/hello
. nginx
Copy code
server {
    listen 80;
    root /gg-host/build;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
        add_header Cache-Control "no-cache";
    }

    location /static {
        expires 1y;
        add_header Cache-Control "public";
    }

    location /api {
        include proxy_params;
        proxy_pass http://api:8080;
    }
}
Python Flask app_info
Copy code
app_info=InputAppInfo(
    app_name="GG-Host",
    api_domain="http://localhost",
    website_domain="http://localhost",
    api_base_path="/api/auth",
    website_base_path="/api/auth"
)
React app_info
Copy code
appInfo: {
    appName: "GG-Host",
    apiDomain: "http://localhost",
    websiteDomain: "http://localhost",
    apiBasePath: "/api/auth",
    websiteBasePath: "/api/auth"
}
r
hey!
On the backend, in appInfo, add the config for
api_gateway_path
and set it to
/api
. The value of
api_base_path
should be set to
/auth
. The react config's apiBasePath should be
/api/auth
and the webisteBasePath should be
/auth
.
You can read more about the api gateway path config here: https://supertokens.com/docs/thirdpartyemailpassword/appinfo#apigatewaypath-optional
h
Still getting 404 with these values πŸ˜•
I'll have a look at that page, thank you.
r
can you enable backend debug logs and show me the output when you call the API?
and also the output when you start the python process.
h
Copy code
* Serving Flask app 'app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
WARNING:werkzeug: * Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
INFO:werkzeug: * Running on http://172.19.0.4:8080/ (Press CTRL+C to quit)
INFO:werkzeug:172.19.0.1 - - [15/Sep/2022 17:44:58] "GET /auth HTTP/1.1" 404 -
INFO:werkzeug:172.19.0.5 - - [15/Sep/2022 17:45:00] "GET /api/auth HTTP/1.0" 404 -
INFO:werkzeug:172.19.0.5 - - [15/Sep/2022 17:45:00] "GET /api/auth HTTP/1.0" 404 -
INFO:werkzeug:172.19.0.5 - - [15/Sep/2022 17:46:26] "GET /api/auth HTTP/1.0" 404 -
INFO:werkzeug:172.19.0.5 - - [15/Sep/2022 17:46:36] "GET /api/auth HTTP/1.0" 404 -
INFO:werkzeug:172.19.0.1 - - [15/Sep/2022 17:46:48] "GET /api/auth HTTP/1.1" 404 -
r
well, those arent our debug logs
checkout the troubleshooting section in the docs to see how to enable them
h
Should I have nginx strip away
/api
with
rewrite ^/api(.*)$ $1 break;
before forwarding the request to my Flask app?
Ah, mb, will do
r
> Should I have nginx strip away /api with rewrite ^/api(.*)$ $1 break; before forwarding the request to my Flask app? You could try that
h
And then just have the app_info like it used to with
/auth
and no api gateway path?
r
if you are stripping away the
/api
, then you need to add that as the api_gateway_path
h
I've tried enabling debug logs with
CMD ["SUPERTOKENS_DEBUG=1", "python", "src/app.py"]
and also:
Copy code
RUN export SUPERTOKENS_DEBUG=1
CMD ["python", "src/app.py"]
But neither seem to work
r
You need to essentially give
SUPERTOKENS_DEBUG=1
as an env variable to the python process - is that how you give env vars?
h
Well, I thought
CMD ["SUPERTOKENS_DEBUG=1", "python", "src/app.py"]
in my Dockerfile would be equivalent to running
SUPERTOKENS_DEBUG=1 python src/app.py
that doesn't seem to be the case. I will try something else.
r
yup
h
r
oh right. you should set api_base_path in python to just
/auth
since api_gateway_path is already /api
h
It is
r
hmmm. let me check
h
And frontend
Ah, sorry, I had commented out the stripping. I will see if the log changes with it enabled
r
frontend should be
/api/auth
for api base path
and backend should be
/auth
for api base path
h
This log is generated when browsing to
http://localhost/api/auth
r
so thats not a valid API we have
do you get back a 400 or 404?
h
400
r
right. so the config is corect now
app should work
h
So then why does
http://localhost/api/auth
not display the login form? πŸ€”
r
the login form is supposed to be displayed on the frontend app
h
That's a 404
r
what path are you serving your react app on?
h
localhost:80/
r
is there only one path in your react app? the
/
route?
or are there others too?
h
This is my current nginx setup. I generate a production build of my React app and then have nginx serve files from the build directory
Copy code
server {
    listen 80;
    root /gg-host/build;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
        add_header Cache-Control "no-cache";
    }

    location /static {
        expires 1y;
        add_header Cache-Control "public";
    }

    location /api {
        include proxy_params;
        proxy_pass http://api:8080;
    }
}
r
well, anyway. You need to server your react app on /auth and /auth/* as well
the login form is handled by the frontend SDK which integrates with your react app
h
Something like this maybe?
Copy code
location /auth {
    try_files index.html =404;
}
r
and /auth/* as well
im not sure about the syntax of nginx here..
but you need to serve the same react app that's being served on
/
on the
/auth
and
/auth/*
route as well (assuming that the websiteBasePath value is
/auth
)
you should checkout tutorials on how to serve a react app on multiple routes via nginx
h
Thanks, I'll look more into it.
r
πŸ‘either way. The api not being found issue has been solved
h
This now shows the login form at
http://localhost/auth
Copy code
location /auth {
    try_files /index.html =404;
}
Can you think of a way I could test for
http://localhost/auth/*
?
r
Not sure. See nginx tutorial
Oh. Sorry misunderstood
h
What I mean is, what from SuperTokens would break
ye
r
Visit /auth/reset-password
And try and do social login flow
h
It's all working fine. Thank you for the assistance! 😁
r
Great!!
5 Views