The request for the specified URL is incorrect

When I send an axios request to an Express URL called "getstatus" in my local development environment, everything works fine. However, once the files are uploaded to a server, the URL path still contains "localhost."

this.$axios.get('api/getstatus', {
}).then(function (response) {
})
.catch(function (error) {
});

app.get('/getstatus', async (req, res) => {
  // code executing here
})

-> Works fine on localhost -> Error on server: Request URL: http://localhost:3000/api/getstatus

Why is the local development URL still being used? It should be

Answer №1

Ensure that the axios get request is pointing to /api/getstatus and not api/getstatus

Additionally, it's recommended to define an API_URL variable in your dot env file. During development, set it to localhost and on the server, set it to your server URL.

Consider this example:

this.$axios.get(`${process.env.API_URL}/api/getstatus`, {
}).then(function (response) {
   // Implement logic here
})
catch(function (error) {
   // Handle errors here
});

Answer №2

Could you attempt the following code modification by utilizing the complete URL in the get request? If successful, consider making the myserver.com parameterized.

this.$axios.get('http://myserver.com/api/getstatus', {
    }).then(function (response) {
})
.catch(function (error) {
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

SignOut operation in Express.js Firebase instantly responds with a status of 200 to the client-side Fetch POST request

I'm currently facing an issue with my POST request setup using the Fetch API in my client-side JavaScript. The request is being sent to my server-side JavaScript code which utilizes Express Js and Firebase Auth. The problem arises when the auth().sign ...

Techniques for ensuring input validity using JavaScript

One of my form inputs is required: <input type="text" id="input-id" required> After the user submits it, I send the value using ajax and then clear it with $("#input-id").val(""). However, after this action, the input appears invalid. I want to ...

Angular post request does not update the table

After displaying a table and a form on a page, I encountered an issue where the table does not update with new data when submitting the form. Even after refreshing the page, the new data is not reflected. As a newbie to Angular, I'm unsure of what exa ...

Setting up and using npm jshint with Grunt and Node.js

I have successfully installed node.js on Windows with the npm package. My project is located in the D drive at D:>projectD I am currently working on running jshint along with SASS, concat, etc. Everything seems to be working fine except for jshint ...

I am looking to trigger the change event from within the click event in Angular

My objective involves detecting when the cancel button is clicked while a file is being uploaded. I am trying to accomplish this by triggering the click event, then monitoring for the change event. If the change event occurs, the document will be uploaded. ...

Obtain the dimensions of the outermost layer in a JSON file

Could you please help me extract the dimensions (600*600) of the outermost layer from the JSON below dynamically? { "path" : "shape\/", "info" : { "author" : "" }, "name" : "shape", "layers" : [ { ...

Error message from FB Messenger bot: Unable to access the property 'object' as it is undefined

I am currently testing my bot using a friend's Facebook account because I cannot locate the message option on my own Facebook page. I have been following the guidelines at https://developers.facebook.com/docs/messenger-platform/getting-started/quick-s ...

Unable to start a download process

The current version of Express being used is 4.16.4 I am trying to create a download function using NodeJs: list.on("click", "a[data-facture]", function () { var facture = $(this).data("facture"); $.ajax({ url: "/track/vehicle/download-i ...

What is the purpose of creating a new HTTP instance for Socket.io when we already have an existing Express server in place?

As I delve into SocketIO, I've combed through various blogs and documentation on sockets. It seems that in most cases, the standard approach involves creating an HTTP server first and then attaching the socket to it as shown below: var app = express() ...

Is there a method to directly download large files from the server without having to wait for the blob response?

I'm currently working on video file requests using axios. I have set the requests with responseType: blob to create a video player once the response is received with window.URL.createObjectUrl(). However, I also have a button that allows the user to d ...

What causes non-reactive variables to act unusual in Vue3?

Check out this code snippet: <template> <input type="button" value="click" @click="clickBtn"/> <div id="reactiveDiv">{{ reactiveVariable }}</div> <div id="noneReactiveDiv"&g ...

ECharts - Version 3.1.6 Event Plugin

I am looking for advice regarding the management of two charts with reference to echars from Baidu (version 3.1.6). Is there a way to control both charts by engaging in a click event on one of them? In simpler terms, how can I capture and respond to the c ...

What is the best way to structure routes in ExpressJS for optimal organization?

As I dive into my first test application using NodeJS, I've hit a roadblock with organizing routes in the ExpressJS framework. For instance, when attempting to create a registration feature, my route looks like this: app.get('/registration' ...

Are you familiar with Vue.JS's unique router options: the 'history' and 'abstract' routers?

Currently, I am developing a VueJS application that involves a 5-step form completion process. The steps are linked to /step-1 through /step-5 in the Vue Router. However, my goal is for the site to return to the main index page (/) upon refresh. One solu ...

Issue with deleting and updating users in a Koa application

My goal is to create a function that deletes a specific user based on their ID, but the issue I'm facing is that it ends up deleting all users in the list. When I send a GET request using Postman, it returns an empty array. What am I doing wrong? I do ...

Is there a way to insert copied links onto separate lines?

I have a list of links to Google search results. I have a checker that allows me to mark the links and copy them. My code is functioning properly, but I want each link to appear on a new line. ... Can someone please help me? I've attempted to add "< ...

Tips for incorporating an entire JavaScript file into a React JS project

I'm facing an issue with a .js file (JavaScript file) that lacks exports code, containing only a constructor and some prototype methods. I am trying to incorporate this file into my ReactJS App. My approach involved adding a script tag in client/inde ...

Exploring the World of Unit Testing with Jasmine and Sinon Factories

At my factory, I have implemented a getter and setter function .factory('myService', function() { var car = null; return { car: car, get: function get() { return car; }, set: function set(newCar) { car = newCar; ...

What is the process for generating a GET request for selected checkboxes and subsequently showcasing the data on an HTML webpage?

Currently working on an app project and need assistance with implementing a feature. I have successfully set up a POST method for the checkboxes that are checked, but I am unsure how to retrieve this data and display it on my HTML page using a GET method ...

What is the best way to switch from using Promise to using await in ES7?

My main issue with Promise is the difficulty in understanding and using resolve and reject. The need to wrap code in Promise can also be cumbersome and forgettable if not used frequently. Additionally, code involving Promise tends to be messy and hard to r ...