Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular http service not responding #69

Closed
shavo007 opened this issue Jul 8, 2015 · 6 comments
Closed

Angular http service not responding #69

shavo007 opened this issue Jul 8, 2015 · 6 comments
Labels

Comments

@shavo007
Copy link

shavo007 commented Jul 8, 2015

Hi,

I have drakov running using grunt on localhost:3000.


[LOG] Setup Route: GET /subscribe Subscribe by email
   Drakov 0.1.8      Listening on port 3000
-- STARTED --

My endpoint I can hit via browser or postman.

Example:

http://localhost:3000/subscribe?id=12345&type=xyz&email=xyz&hv=xyz

But when I try and call the api in angular, in the server console it logs continuously:

[LOG] OPTIONS /subscribe?id=12345&type=xyz&email=xyz&hv=xyz

Code snippet angular:

 $http.get('http://localhost:3000/subscribe?id=12345&type=xyz&email=xyz&hv=xyz', {headers: {
        'Custom-Header': 'a'}})
        .success(function (response) {
          console.log('Response ' + response);
        });

My grunt config:

 grunt.registerTask('mock-api', 'Start drakov server', function() {
    var done = this.async();

    var drakovOptions = {
      sourceFiles: './doc/*.md',
      serverPort: 3000
     // autoOptions: true
      //disableCORS: false
    };

    drakov.run(drakovOptions, function(err){
      console.log('-- STARTED --');
      if (err) {
        throw err;
      }
    });
    done();
  });

NB: My angular app is running on a different port using connect on port 9000.

@shavo007
Copy link
Author

shavo007 commented Jul 8, 2015

I have got a bit further but not much!
In the response I added in two headers:

+ Headers

            Access-Control-Allow-Origin: *
            Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept

Angular http service now calls get instead of options but it just keeps looping and inevitably crashes!!!

[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email
[LOG] GET /subscribe?id=12345&type=xyz&email=xyz&hv=xyz
[DRAKOV] GET /subscribe{?id,type,email,hv} Subscribe by email

@shavo007
Copy link
Author

shavo007 commented Jul 8, 2015

i think instead of adding in the custom headers to the blueprint file, i need to work out for local development how to host drakov and grunt connect on the same domain (localhost). I think i need a proxy!!!

@yakovkhalinsky
Copy link
Contributor

CORS is enabled by default, so I'm not sure if I can explain why it doesn't respond.

Are you able to post the endpoint snippet from the markdown file?

@shavo007
Copy link
Author

shavo007 commented Jul 9, 2015

Cheers for the reply mate.

This is my code snippet from my .md file.

# Group Subscriptions


## Subscription  [/api/subscribe{?id,type,email,hv}]


+ Parameters
    + id (string, `12345`, required) ... Tracking number(s) [delimiter is ',']
    + type (string, `xyz`, optional) ... the type of the item represented by the id field. If this is populated, id is expected to be a single  track  number.
    + email (string, `z.dead@g.com.au`, optional) ...  the email address to which track advice will be sent
    + hv (string, `xyz`, optional) ... the hash used to validate the id and email address fields



### Subscribe by email [GET]

+ Response 200

    + Headers

            content-type: application/json

    + Body

              {
                  "QueryTrackEventsResponse": {
                      "TrackingResult": {
                          "ReturnMessage": {
                              "Code": "ESB-10000",
                              "Description": "Success"
                          },
                          "TrackingID": "xxx",
                          "ArticleDetails": {
                              "ArticleID": "xxx",
                              "EventNotification": "00",
                              "ProductName": "International",
                              "ClientStatus": "None",
                              "EventCount": 0
                          }
                      }
                  }
              }

In the server log I see:

[LOG] Setup Route: GET /api/subscribe Subscribe by email

I have added in the config to use a connect-proxy.

Once I did this, it resolved the issue!!!

This is a snippet of the proxy config in my gruntFile.js

     proxies: [{
        context: '/api', // the context of the track microservice api
        host: 'localhost', // wherever the data service is running
        port: 3000 // the port that the microservice is running on
      }],

Do you believe I do not need the proxy?

@yakovkhalinsky
Copy link
Contributor

sorry for the late reply, we use Drakov with protractor tests that run static Angular.js interfaces with no need of a proxy.

Maybe the proxy is modifying the headers somehow.

@shavo007
Copy link
Author

From what I read, you need a proxy when you are running a back-end server to prevent CORS.

Closing as the above plugin worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants