1

I am doing a tutorial on React with Reflux. But Im getting a 404 on the query response. I think it has todo with the url sent to fetch the data.

When I do a console.log on the variable 'url' I get the following:
api.openweathermap.org/data/2.5/forecast?appid=4e26b7e43fe918dbc620bbf34456a9de&q=New York,us
but in the Network Request tab I see the following in the Request

Request URL:http://localhost:8080/api.openweathermap.org/data/2.5/forecast?appid=4e26b7e43fe918dbc620bbf34456a9de&q=New%20York,us
Request Method:GET
Status Code:404 Not Found
Remote Address:127.0.0.1:8080

If I copy this address and paste it into the address bar, sure thing I dont get a respons, but if a delete the localhost:8080 from the address, I get a perfect response from the API.

Why is the localhost:8080 being added, and if it is wrong how do I fix it?

Here is my Action that I created to go and fetch the data.

ACTION:

import axios from 'axios';
const API_KEY = '4e26b7e43fe918dbc620bbf34456a9de';
const ROOT_URL = `api.openweathermap.org/data/2.5/forecast?appid=${API_KEY}`;

export const FETCH_WEATHER = 'FETCH_WEATHER';

export function fetchWeather(city) {
    var url = `${ROOT_URL}&q=${city},us`;

    const request = axios.get(url);

    return {
        type: FETCH_WEATHER,
        payload: request
    };
}

This worked, but can anyone explain why maybe?
on the url variable, I manually added http:// and this then caused the url request not to prepend http://localhost:8080

import axios from 'axios';

const API_KEY = '4e26b7e43fe918dbc620bbf34456a9de';
const ROOT_URL = `api.openweathermap.org/data/2.5/forecast?appid=${API_KEY}`;

export const FETCH_WEATHER = 'FETCH_WEATHER';

export function fetchWeather(city) {

    var url = `http://${ROOT_URL}&q=${city},us`;

    const request = axios.get(url);

    return {
        type: FETCH_WEATHER,
        payload: request
    };
}
morne
  • 4,035
  • 9
  • 50
  • 96
  • 1
    This behaviour is related to the library that you're using to make the request (axios). Take a look at the help info on 'axios'. Especially the info about 'baseURL'. https://github.com/mzabriskie/axios#request-config – Björn Boxstart Jun 21 '16 at 12:23

0 Answers0