-1

I am learning VueJS and wanted to make a project. So I've to get data from ExpressJS server/API. I've tried vue-resource and axios. both of them returned status code 0.

I think my API is not responding correctly to HTTP requests.

What should I concentrate on while building API.

P/S: Sorry, can't upload any code, because I'm using different computer.

  • `because I'm using different computer.` then go to the other computer. We will still be there until you arrive :) – Jonas Wilms Jun 01 '18 at 15:33

2 Answers2

0

Your question is not clear. However, you mention this:

I think my API is not responding correctly to HTTP requests.

This may be the case and that would mean that your Express server is not running as expected. The causes I could think of for this are:

  1. You are not listening on port 8081, but rather on other port and you have not noticed this. If you used Express-generator, the default port is 3000.
  2. You are not calling the correct route from the front-end. Make sure that you are trying to access the correct url. For example you may have done the routing as follows:

    localhost:8081/api/foo

    and later be calling:

    localhost:8081/foo

    expecting to get a correct answer...

I would recommend to debug your server. Check the logs! I really doubt your problem has to do with your front-end framework.

-1

I fixed it with

res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST'); res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, \Authorization');