PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 13, 2022

[FIXED] Why would nuxt axios be calling the wrong server middleware API?

 October 13, 2022     axios, nuxt.js     No comments   

Issue

I recently split my Nuxt API into several files for easy management. However, it seems that when I make my calls, it sometimes calls into the wrong file.

In my nuxt.config.js, I have

serverMiddleware:[
    {path:"/user-api",handler:"~/api/user.js"},
    {path:"/blog-api",handler:"~/api/blog.js"},
    {path:"/calendar-api",handler:"~/api/calendar.js"},
    {path:"/gallery-api",handler:"~/api/images.js"},
    {path:"/product-api",handler:"~/api/product.js"},
    {path:"/video-api",handler:"~/api/video.js"},
    {path:"/printful-api",handler:"~/api/printful.js"},
    {path:"/review-api",handler:"~/api/reviews.js"},
    {path:"/email-api",handler:"~/api/email.js"},
    {path:"/search-api",handler:"~/api/search.js"},
    {path:"/requirement-api",handler:"~/api/requirements.js"},
  ]

Then when I load in my desired page

this.video = await this.$axios.$get('/video-api/title',{params:{title:this.$route.params.title}})

It ends up calling the wrong file:

  Error... at async api\requirements.js:55:12

Any reason why it would be doing this?


Solution

It appears that simply having the same end path causes it confusion. Changing the call (and api obviously) to

this.video = await this.$axios.$get('/video-api/videotitle',{params:{title:this.$route.params.title}})

so that the final part of the call is unique, fixes the problem. Can't say it's ideal, but it does work. I found this out because it also had other problems mixing up blog-api/title as well



Answered By - awsirkis
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing