APIs keep returning 404 error
I've been using chatgpt to write an OAuth integration with Notion. (my app needs access to Notion). However, I keep getting a 404 error whenever I try to do any api calls. I even have a foobar function & endpoint and it gets the same result. I've double checked all Notion API related configurations like client IDs, etc and made sure they are all correct. For the notion authorization, it is the callback that is failing. After authorizing Notion, it redirects to
http://localhost:3000/api/auth/notion/callback?code=03ed839c-59bf-41a9-9d9b-e4a5697e9d03&state=
but the UI shows a 404 error. In Postman, it shows the html from main.wasp and a "You need to enable JavaScript to run this app." message.
I am using wasp 0.16.0 on macos (m1 pro macbook pro)
18 Replies
Hi @Sean. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in your question and the knowledge sources available, it appears that you're encountering a 404 error with your API calls, including a custom
fooBar
endpoint and the Notion OAuth callback. Let's address this issue step by step:
1. CORS Configuration:
One common reason for API 404 errors in Wasp is incorrect CORS configuration. As mentioned in the Custom HTTP API Endpoints documentation, APIs in Wasp don't utilize the default middleware like Operations do. You need to ensure CORS is enabled for your APIs.
To fix this, you can define custom middleware for your APIs in the Wasp file. Here's an example:
Then in your src/apis.ts
file:
2. API Declaration:
Make sure your API declarations in the Wasp file are correct. For the Notion OAuth callback, you might want to use api
instead of apiNamespace
:
3. Trailing Slash Issue:
There's a known issue with Wasp where URLs with trailing slashes can result in 404 errors. Make sure your API endpoints don't have trailing slashes. If they do, remove them and try again.
4. Server-Side Rendering:
The message "You need to enable JavaScript to run this app" suggests that your app might be trying to render on the server side. Wasp primarily focuses on client-side rendering, so make sure your app is configured correctly for client-side rendering.
5. Version Compatibility:
You mentioned using Wasp 0.16.0. Make sure all your code and configurations are compatible with this version. Sometimes, examples or generated code might be for different versions, causing issues.
6. Debugging:
To further debug this issue, you can add console logs in your API implementations to see if they're being reached. Also, check your server logs for any error messages that might provide more insight.
If after applying these suggestions you're still encountering issues, it might be helpful to share more of your implementation details or the full error logs. The Wasp team is also working on improving error messages related to path configurations, which should make debugging easier in future versions.
Custom HTTP API Endpoints documentation
Configuring Middleware documentation
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sean, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?@kapa.ai can you provide example cors configuration?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Certainly! I'd be happy to provide an example of CORS configuration in Wasp. Here's a typical CORS configuration that you can use as a starting point:
This configuration does the following:
1. It allows requests from the frontend URL (which Wasp automatically sets) and two additional example domains.
2. It allows GET, POST, PUT, DELETE, and OPTIONS HTTP methods.
3. It allows the 'Content-Type' and 'Authorization' headers.
To use this configuration, you would need to add it to your Wasp file like this:
Remember to adjust the allowed origins, methods, and headers according to your specific needs.
For more detailed information and examples, you can refer to the Configuring Middleware documentation.
If you need to configure CORS for specific API routes or namespaces, you can use the
apiNamespace
feature as mentioned in the Custom HTTP API Endpoints documentation.
Then in your implementation file:
This approach allows you to have different CORS configurations for different parts of your API if needed.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sean, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?@kapa.ai i dont think this is a cors/middleware issue. I still get a 404 error on redirect from Notion
Let me check the knowledge base for you again. One moment! :books:
Wohooo @Sean, you just became a Waspeteer level 1!
----------------------
I apologize for the confusion in my previous response. You're right that this might not be a CORS/middleware issue, especially since you're getting a 404 error on redirect from Notion. Let's focus on the OAuth callback issue you're experiencing.
Based on the information you provided earlier, it seems the problem is specifically with the Notion OAuth callback. When Notion redirects to
<http://localhost:3000/api/auth/notion/callback?code=...
,> you're getting a 404 error. This suggests that the route is not being recognized by your Wasp application.
Here are a few things to check:
1. Route Definition:
Make sure your route is correctly defined in your main.wasp
file. The API definition you provided earlier looks correct:
2. File Path:
Ensure that the file path in the import statement is correct. The file @src/server/notion.ts
should exist and contain the notionOAuthCallback
function.
3. Function Implementation:
Check that the notionOAuthCallback
function is correctly exported from the notion.ts
file:
4. Server Restart:
After making changes to your Wasp file or server-side code, make sure to restart your Wasp server to apply the changes.
5. URL Matching:
Double-check that the callback URL you've registered with Notion exactly matches the URL in your Wasp application, including the protocol (http/https) and any subdomains.
6. Server Logs:
Check your server logs when the redirect happens. There might be error messages that can provide more insight into why the route isn't being recognized.
If you've verified all these points and are still experiencing the 404 error, it might be helpful to create a minimal reproducible example of your Wasp application that demonstrates this issue. This would allow the Wasp team to investigate further.
Also, consider checking the Github issues for Wasp to see if there are any known issues related to API routing or OAuth callbacks in your version of Wasp (0.16.0).
If the problem persists, you might want to reach out to the Wasp team directly through their Discord channel or by opening an issue on GitHub, as this could potentially be a bug in Wasp itself.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sean, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?hopefully someone will chime in soon, none of the suggestions from AI (the bot or chatgpt) are working.
hey 404 usually means the page you're reaching is not there.... (server error)
i think your api middleware configuration might need changes...
sounds like it could be your Notion Auth configuration. What address did you use for the callback url in the notion oauth app you configured?
what happens when you do a CURL request to the webhook address:
curl -X POST http://localhost:3001/auth/notion/callback
ah btw, shouldn't it be a POST request? (cc: @miho)Very funny, i have this exact same problem and it took me days to solve. Vinny added the key code here - it's 3001 not 3000
Yeah, that happens a lot. People send the request to their client, not their server.
Claude kept on saying it's fine! O3 mini was like uh, it's 3001
yeah i like o3 for figuring out problems, and then claude for implemeting the solution
In addition to setting the correct port, I think you also need to double-check your callback URL path in Notion. You said:
After authorizing Notion, it redirects to http://localhost:3000/api/auth/notion/callback?code=03ed839c-59bf-41a9-9d9b-e4a5697e9d03&state=
But you’ve defined your route as:
So the URL should actually be http://localhost:3001/auth/notion/callback
good catch
thank you all for the help! Indeed i was using the port for the client, not the server and the routes were misaligned.
Glad we could help 🙂