1

I'm very new to http request and am trying to get data with https://darksky.net/dev/docs/faq. They don't support CORS and suggest that I have to use a proxy server to get their data.

I'm using Angular and am using a service for the http request:

import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';

@Injectable()
export class ServiceWeather { // Unconventional but I see all my services when typing service
    constructor(private http: Http) { }

    private weatherUrl = 'https://api.darksky.net/forecast/[key]/[latitude],[longitude]'

    public getWeather(): Promise<any> {
        return this.http.get(this.weatherUrl)
                .toPromise()
                .then(response => response.json().data)
                .catch(this.handleError);
    }

    private handleError(error: any): Promise<any> {
        console.error('An error occurred', error);
        return Promise.reject(error.message || error);
    }
}

How can configure this with a proxy server?

Helpful Extra Info Needed: What proxy server services should I use for development?

4
  • 2
    As stated, you need a proxy server. You can't do that on the client side. Commented Jul 31, 2017 at 6:47
  • Just shows how much I don't understand. How can I do that to accomplish my goal? Can you point me to some tutorials or sources I should read up on? Commented Jul 31, 2017 at 6:53
  • So the question is totally irrelevant to Angular. Google for 'cors proxy' and select one that suits your server setup. Commented Jul 31, 2017 at 6:55
  • Google it. If you still can't figure out. Then that's the time you would post a question along with your attempted solutions. Commented Jul 31, 2017 at 6:55

1 Answer 1

1

Thanks for the comment on 'Cors Proxy'.

I had found the service: http://cors-proxy.htmldriven.com and was able to get data from darksky by using their url.

private weatherUrl = 'http://cors-proxy.htmldriven.com/?url=https://api.darksky.net/forecast/[key]/[latitude],[longitude]'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.