Showing posts with label access. Show all posts
Showing posts with label access. Show all posts

Jun 14, 2013

Meteor. Request to host is not allowed by Access-Control-Allow-Origin.

As a novice I'd like to describe a situation when you may need to make calls to a different domain. In my case it was a requirement to access external API. Anyway I'd like to describe here my perspective of usage this in meteor. You would need to get those data and parse them. First thought is to use client. Wrong. You would need to add CORS support to your application.
It means you need to have header Access-Control-Allow-Origin: * added to all of your response objects. This will enable Meteor usage of external domain responses. And requires you to hack Meteor code.

But there is more "proper" way to work with server. Code on a server is executed synchronously and so you can be sure it will be executed and result returned.
So. First we need to make sure we have a Meteor.http package installed. You can install it by executing "meteor add http" in your project root directory.
Meteor.http can work in both synchronous and asynchronous modes. It is differed by defining a callback function to a http.call() method. In our example we will make a http request on external server and work with it on a client.
Here is your client and server code:
url = 'http://.........'

if (Meteor.is_client) {

    // Calling our Meteor server's function 
    // and simply storing data into current session
    Meteor.call('fetchDataFromUrl', function (error, response) {
        Session.set('external_server_data', response)
    });


    // Providing meteor data for template (it renders on data received)
    Template.data.server_data = function () {
        return Session.get('external_server_data');
    };

}

if (Meteor.is_server) {

    Meteor.methods({
        // Declaring a method
        retrieve_doc_types: function () {
            this.unblock();
            return Meteor.http.get(api_url);
        }
    });
    
}
And the template to display their result:
<head>
    <title>data from your server</title>
</head>

<body>
 <h1>Data from your server:</h1>
 {{> data}}
</body>

<template name="data">
 {{server_data}}
</template>
It was quite enough to me to make calls to external API. You can also add something like JSON.parse somewhere in server side to make your data posted in a proper manner. But it is out of the scope of this article. Also please note this.unblock(); method.

Please comment/suggest!

Jul 9, 2012

Blocking iOS to acces Contacts freely


There are lots of occasions when you want to be private in the net. Now it's common to say "Anonymous". Many people do not even think it's important. I, personaly, dislike facebook, skype, twitter, any else third party... having my contacts list synched to their server without even telling me... I do not want to be truly anonymous, you know... Have nothing to hide really. But I want that really smal confirm that Skype, for e.g. would take my contacts and for what reason. 

Facebook was first, as usual... They've done it. I really deleted their app from my iOS devices first. But instead of taking lessons from their mistakes... All huge companies gone wild about this possibility to copy some new ammount of user data... Skype was second (for me)... Then LinkedIn... However they warned and I've agreed... So nothing really bad to say about them. But MS is such a Microsoft... They want me to "skype" instead of "calling" my friends through my Apple/Android device :)...

Anyway I've decided I really need something like a hardware switch to grant access to my contact list on iDevices... And it is really done for us already...

You need a Jailbreak for this! (As I had one already wont mention it here. I think there are lots of info in the net about it)

ContactPrivacy tweak. For now, that I'm writing this article... It exists in BigBoss repo, that is default set in Cydia AFAIK. And you suppose to have access to it without adding any repositories. So typing in Cydia search: "ContactPrivacy" (without scopes) should reveal it without any problems.

After installing it you will probably see something like this:
So ...... you Skype after installing it. :)

Note: That I think it's good idea to install this tweak even before any other APP is installed. I'd do so if I only knew before.

Heard somewhere about Twitter is going to have my contacts too... Wtf? Why Twitter wants them too... Can't even imagine... Who's next. "Corporation of all good". Nahh... I think they already have them but not so dumb to tell >:) But somehow it does disturb me less...

BTW it's a nice reason to make a jailbreak for this tweak. Why not make it standard in iOS?
How do you think?