N
Nuxt4d ago
Bread

server route not being hit

I have a server route: server/api/dealer/[dealerId]/member/[memberId]/changerole.ts The below code always sends a request to another one, which I for the life of me can't find anywhere. This is what actually is called: server/api/content/index.get.ts :

ERROR Request failed with error: [GET] "/api/content?path=%2Fapi%2Fdealer%2F7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b%2Fmember%2F878a7c20-3159-4627-b70e-d80c6b398754%2Fchangerole&includeAncestors=true": 404 Not Found

ERROR [nuxt] [request error] [unhandled] [404] [GET] "http://localhost:11812/umbraco/delivery/api/v2/content/item/api/dealer/7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b/member/878a7c20-3159-4627-b70e-d80c6b398754/changerole?path=%2Fapi%2Fdealer%2F7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b%2Fmember%2F878a7c20-3159-4627-b70e-d80c6b398754%2Fchangerole&includeAncestors=true": 404 Not Found

ERROR Request failed with error: [GET] "/api/content?path=%2Fapi%2Fdealer%2F7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b%2Fmember%2F878a7c20-3159-4627-b70e-d80c6b398754%2Fchangerole&includeAncestors=true": 404 Not Found

ERROR [nuxt] [request error] [unhandled] [404] [GET] "http://localhost:11812/umbraco/delivery/api/v2/content/item/api/dealer/7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b/member/878a7c20-3159-4627-b70e-d80c6b398754/changerole?path=%2Fapi%2Fdealer%2F7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b%2Fmember%2F878a7c20-3159-4627-b70e-d80c6b398754%2Fchangerole&includeAncestors=true": 404 Not Found
var route = "/api/dealer/7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b/member/878a7c20-3159-4627-b70e-d80c6b398754/changerole";
console.log('fetching, ', route)
const {data} = await useFetch(route, {
method: 'POST',
body: 'Manager',
});
var route = "/api/dealer/7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b/member/878a7c20-3159-4627-b70e-d80c6b398754/changerole";
console.log('fetching, ', route)
const {data} = await useFetch(route, {
method: 'POST',
body: 'Manager',
});
Why would my server route not be being hit?
3 Replies
kapa.ai
kapa.ai4d ago
Hi @Bread. 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 seems that your server route is not being hit due to a mismatch between the expected route and the actual request being made. Let's break down the issue: 1. Your server route is defined as: server/api/dealer/[dealerId]/member/[memberId]/changerole.ts 2. The request you're making in your code is: /api/dealer/7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b/member/878a7c20-3159-4627-b70e-d80c6b398754/changerole This route should match your server route definition. However, the error message shows a different request being made:
<http://localhost:11812/umbraco/delivery/api/v2/content/item/api/dealer/7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b/member/878a7c20-3159-4627-b70e-d80c6b398754/changerole?path=%2Fapi%2Fdealer%2F7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b%2Fmember%2F878a7c20-3159-4627-b70e-d80c6b398754%2Fchangerole&includeAncestors=true>
<http://localhost:11812/umbraco/delivery/api/v2/content/item/api/dealer/7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b/member/878a7c20-3159-4627-b70e-d80c6b398754/changerole?path=%2Fapi%2Fdealer%2F7fdae06b-c9d0-4d6e-a0ed-d8678e499e1b%2Fmember%2F878a7c20-3159-4627-b70e-d80c6b398754%2Fchangerole&includeAncestors=true>
This URL is significantly different from what you intended, which explains why your server route is not being hit. The issue might be related to how useFetch is handling the route. According to the Nuxt documentation on useFetch, the useFetch composable is meant to be used in a setup function, plugin, or route middleware. It's possible that there's some configuration or middleware that's altering the request URL. To troubleshoot this issue: 1. Make sure you're not using any proxy or rewrite rules that could be modifying the request URL. 2. Check your Nuxt configuration file (nuxt.config.ts) for any serverMiddleware or other configurations that might be affecting the API routes. 3. Try using $fetch instead of useFetch to see if the issue persists. Here's an example:
const response = await $fetch(route, {
method: 'POST',
body: 'Manager',
});

const response = await $fetch(route, {
method: 'POST',
body: 'Manager',
});

4. Ensure that your server route file is correctly named and placed in the right directory structure. 5. Double-check that you're not accidentally importing or using a different fetch function that might be causing this behavior. If the issue persists after trying these steps, you might need to investigate further into your project's configuration and middleware. The error suggests that the request is being redirected to an Umbraco API, which isn't mentioned in your original route definition. Nuxt Server Directory Structure documentation might be helpful for ensuring your server routes are set up correctly. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4d ago
<@280730525960896513> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Bread
BreadOP4d ago
None of those points help 😦 all been validated. Even using the $fetch makes the same request!

Did you find this page helpful?