Meteor.http.call() from my app.meteor.com - javascript

I have an application where I use Meteor.http.call() in a server side function.
var ret = Meteor.http.call("GET", "https://www.quandl.com/api/v1/datasets/SF1/<...>");
This works using a localhost meteor server: I have my data back in the ret variable.
I deployed the application to ruleoneinvesting.meteor.com and now I get this error using that same call:
XMLHttpRequest cannot load https://ddp--4645-ruleoneinvesting.meteor.com/sockjs/info?cb=p7czcbhqun. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ruleoneinvesting.meteor.com' is therefore not allowed access. The response had HTTP status code 503.
This didn't helped.

Sorry, my fault. I was using a
fs.writeFile('../../../../../../data/')
in a folder that it was not allowed to write in *.meteor.com.
That caused the HTTP status code 503.

Since you're getting "HTTP status code 503", this may not be something you can or need to fix.
According to wicked peter, the problem may not be yours but the server's:
503 Service Unavailable
The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state

Related

something wrong with jsonp data, How to get the data

But it returns -403 why
but when I click that, It comes out this
how can I get the message
The HTTP 403 Forbidden client error status response code indicates that the server understood the request but refuses to authorize it.. After one-line check with Fetch API the answer is: server is not handling Cross Origin Resource Sharing - making cross-origin AJAX is not possible. You can avoid it by using simple local HTTP server (e.g. in Python) to get data from server (e.g. with requests) and self-serve it (e.g. with Flask).
Check it in JS console:
fetch('https://api.bilibili.com/x/web-show/res/loc?jsonp=jsonp&pf=7&id=1695').then(r=>r.json()).then(json=>console.log(json))

'Access-Control-Allow-Origin' error when getting data from the API with Axios (React)

I'm getting an a "XMLHttpRequest cannot load https://example.com. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access."
This is my componenDidMount(), and I'm using axios to get the data from my API.
componentDidMount() {
this.serverRequest = axios.get(this.props.source).then(event =>{
this.setState({
title: event.data[0].name
});
});
}
I'm using "python -m SimpleHTTPServer" on the terminal, to run 'http://localhost:8000'.
I'm using the Chrome browser, and if I turn on the Chrome CORS plugin (to enable cross origin resource sharing), the app works, and I see data displayed from the API on the DOM. But I know that using the CORS plugin is bad, so how should I fix the 'Access-Control-Allow-Origin' error officially?
With Axios, can I somehow add dataType: "jsonp", if that would fix it?
This is a restriction made by the browser for security reasons when you try to access content in some domain from another domain. You overcome this, you need to set the following in your header
Access-Control-Request-Method
Access-Control-Request-Headers
Many sites restrict CORS. The best way to achieve your goal is to make your python server as a proxy. See the example.
//Request from the client/browser
http://localhost:8000/loadsite?q=https%3A%2F%2Fexample.com
//In your server
1. Handle the request
2. Get the query param(url of the website)
3. Fetch it using your python server
4. Return the fetching data to the client.
This should work.

No 'Access-Control-Allow-Origin' header is present on the requested resource despite it is there

I have java application exposing its api as rest services. It is accessible on the following URL: http://localhost:8080
On the other hand I have Angular standalone client trying to call those services. This client is operating on different URL: http://localhost:8383
To avoid CORS issue I have added this to the response header of my rest services:
return Response.ok(result,
MediaType.APPLICATION_JSON).header("Access-Control-Allow-Origin",
"http://localhost:8080").build();
Now it appears no matter what I put as a value of this header:
http://localhost:8080
http://localhost:8383
(* - star)
client doesn't work complaining for the lack of this header:
XMLHttpRequest cannot load http://localhost:8080/PokerGame-REST. No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:8383' is therefore not allowed
access. (16:24:11:684 | error, javascript) at app/index.html
What is the problem here, did I miss something?
It's worth mentioning that Advanced REST client returns the response as expected and the response headers contain this one: Access-Control-Allow-Origin. So it looks like purly my Angular app issue but why?
Another interesting thing is client behavior. When I use:
$http.get('http://localhost:8080/PokerGame-REST/').success(function
(response) { ... }
it fails with the error in question but when I use this:
var restCall = $resource('http://localhost:8080/PokerGame-REST/', {});
restCall.get(function (restResponse) { $scope.intro = restResponse; });
it fails with different error:
Response for preflight is invalid (redirect)
which is not true as the response is purly in JSON format.
Any ideas?
PJDef was right (second comment) and his suggestion helped me to resolve the issue.

How to make cross origin get request via angularjs http using food2fork api

I'm simply trying to make a get request using food2fork's search api in an angular app. Right now I've got no backend to the app, so everything is running client side, and I'm running the following (with the APIKEY replaced, of course):
$http.jsonp('http://food2fork.com/api/search?q=turkey&key=APIKEY&callback=jsonp_callback')
.then(function(response) {
console.log(response);
});
However, I'm Uncaught SyntaxError: Unexpected token : in the console. I assume this is because it's expecting a jsonp function rather than json.
If I run it as a jquery getJSON, as seen here:
$(document).ready(function() {
var url = "http://food2fork.com/api/search?q=turkey&key=APIKEY";
$.getJSON(url,function(data) {
})
});
I get No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8080' is therefore not allowed access. - which may be because I'm running locally, but that hasn't been a problem in the past.
I just want to get the json that I get if I run the same request as a url in a browser. Any ideas?
No 'Access-Control-Allow-Origin' header is present on the requested resource
You are facing Cross Domain problem and what you should do is enabling CORS from your server side (the service running from localhost:8080)

Why would XML be an issue with a MEAN stack application, and what is this error about?

I am currently working on a socket.io "hello world" via a MEAN stack application, and right away Chrome is tossing some funky errors my way. To be honest, in the debugging effort, I'm not sure even where to begin. My initial questions were:
Why is XML being used instead of JSON?
What does No 'Access-Control-Allow-Origin' header is present on the requested resource. even mean?
The entire error message is below, and thanks in advance for any advice y'all are able to give.
Cheers,
Peter
XMLHttpRequest cannot load http://localhost/socket.io/?EIO=3&transport=polling&t=1435600202687-6. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access. The response had HTTP status code 404.
Try including the socket.io lib directly from the socket server:
<script src="http://localhost:9000/socket.io/socket.io.js"></script>
The Error "No 'Access-Control-Allow-Origin' header is present on the requested resource." means that your server doesn't allow an extern resource to connect.
Additionally you can set the allowed origins directly in the io setup e.g:
var io = require('socket.io')(server, {origins:'page.com:* http://page.com:* http://www.page.com:*'});

Categories

Resources