Can't get apiNamespace working in OpenSaas
Trying to set up API namespace, but
curl -v http://localhost:3000/api/
returns landing page HTML instead of hitting my API.
main.wasp
middleware (apiKeyAuth.ts)
curl response
Issues:
• Middleware isn’t logging, so it might not be running.
• curl returns the landing page instead of API response.
Questions:
• Any ideas why it's not working?
• How to get access to entity inside middleware?2 Replies
Hi @Alex. 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 the knowledge sources, I can offer some insights into your issues with the
apiNamespace
in OpenSaaS. Let's address your questions and problems:
1. Why it's not working:
The main issue seems to be that your API namespace configuration is not being applied correctly. There are a few potential reasons for this:
a) Path configuration:
Your apiNamespace
is set to /api
, but you're making a request to <http://localhost:3000/api/
.> The trailing slash might be causing issues. Try removing it and make the request to <http://localhost:3000/api
> instead.
b) Port mismatch:
You're making the request to port 3000, which is typically the client-side port in Wasp applications. The server usually runs on port 3001. Try changing your curl command to:
c) Middleware configuration:
Your middleware configuration looks correct, but it's possible that it's not being applied properly. Make sure that your apiKeyAuth.ts
file is in the correct location (typically src/server/middlewares/
).
2. Getting access to entities inside middleware:
To access entities inside your middleware, you need to modify your middleware function to accept a context
parameter. Here's how you can do it:
To further debug your issue, I recommend the following steps:
1. Double-check that you're making the request to the correct port (3001 for the server).
2. Ensure that your apiNamespace
configuration is in the correct place in your main.wasp
file.
3. Try adding a more specific path to your apiNamespace
, for example:
Then make your request to <http://localhost:3001/api/v1
.>
4. Check your server console for any error messages that might provide more information about why the middleware isn't being applied.
If you're still having issues after trying these suggestions, it might be helpful to create a minimal reproducible example and share it with the Wasp community for further assistance.
For more information on configuring middleware in Wasp, you can refer to the Configuring Middleware documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Alex, 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?ohh, my. the port was an issue