Trouble with API Route Not Being Recognized in Remix App #9403
Unanswered
drewkovihair
asked this question in
Q&A
Replies: 1 comment
-
Are you looking for API proxy? If you just want API proxy in dev mode, you can put this to your vite.config.ts:
For the production, you can use remix express template and add http-proxy to the server.js to proxy API: import httpProxy from 'http-proxy';
const apiProxy = httpProxy.createProxyServer();
app.all('/api/*', function (req, res) {
apiProxy.web(req, res, { target: 'YOUR API URL' });
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm experiencing an issue where my API route isn't being recognized when placed within the routes/api directory of my Remix app. Here’s the context:
File Structure:
I have the file approveProSubmission.js in both the routes/ and routes/api directories.
When I make a POST request to /approveProSubmission, it works fine.
However, moving it to the api folder and adjusting the fetch to /api/approveProSubmission results in a 404 error.
Behavior:
The route works perfectly when placed directly under the routes/ directory.
Placing it under routes/api and accessing it via /api/approveProSubmission leads to a "No route matches URL" error.
Error Message:
I suspect there might be an issue with how I'm configuring or exporting the route in the api directory. Here is how I'm currently setting it up:
approveProSubmission.js:
Additionally, here’s how I’m calling the API from the client-side:
This function works perfectly when the route is placed directly under the routes/ directory but fails with a 404 error when it's moved to routes/api/, despite updating the fetch URL to /api/approveProSubmission
Could anyone suggest what I might be doing wrong or provide insight into why the route isn't recognized under the api directory? Any advice or guidance would be greatly appreciated!
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions