Proxy request on firebase - json

I have created a project using Ionic and deployed it as a PWA to firebase. I have got around CORS utilising a proxy to call google maps api sevices. This works locally however once deployed this is no longer the case.
The response I am getting on the server is:
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at XMLHttpRequest.l (https://atomic-affinity-127705.firebaseapp.com/build/vendor.js:1:312114)
at t.invokeTask (https://atomic-affinity-127705.firebaseapp.com/build/polyfills.js:3:15660)
at Object.onInvokeTask (https://atomic-affinity-127705.firebaseapp.com/build/vendor.js:1:26996)
at t.invokeTask (https://atomic-affinity-127705.firebaseapp.com/build/polyfills.js:3:15581)
at r.runTask (https://atomic-affinity-127705.firebaseapp.com/build/polyfills.js:3:10834)
at e.invokeTask [as invoke] (https://atomic-affinity-127705.firebaseapp.com/build/polyfills.js:3:16794)
at p (https://atomic-affinity-127705.firebaseapp.com/build/polyfills.js:2:27648)
at XMLHttpRequest.v (https://atomic-affinity-127705.firebaseapp.com/build/polyfills.js:2:27893)
"Http failure during parsing"
When looking at the text field I get the contents of my index.html page being parsed. Starting with the Doctype explaining why the error fails on <.
Ionic.config.json has the following:
"proxies": [{
"path": "/api",
"proxyUrl": "https://maps.googleapis.com/"
}]
and is called as such:
/api/maps/api/place/nearbysearch/ ....etc
Any help would be greatly appreciated.

For those that are interested in this solution, I ended up utilising the js libraries provided by Google. The alternative to get around this is create a functions set on firebase and run express to do the calls for with the appropriate CORS headers however I didn't want to add extra calls in.

Related

Laravel + Vue Error in render: "SyntaxError: Unexpected token u in JSON at position 0"

I have a Laravel application with Vue js and until a while ago it was working perfectly. Now when I go to any page that uses Vue js this error appears: [Vue warn]: Error in render: "SyntaxError: Unexpected token u in JSON at position 0".
When I reload the page by clearing the cache (Control + Shift + R on Mac OS) it works again, but when I update without this command the error appears again.
PS: I didn't do any package updates for both laravel and npm, it just stopped working out of nowhere.
Try this in the console:
JSON.parse(undefined)
Here is what you will get:
Uncaught SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at <anonymous>:1:6
In other words, your app is attempting to parse undefined, which is not valid JSON.
There are two common causes for this. The first is that you may be referencing a non-existent property (or even a non-existent variable if not in strict mode).
window.foobar = '{"some":"data"}';
JSON.parse(window.foobarn) // oops, misspelled!
The second common cause is failure to receive the JSON in the first place, which could be caused by client side scripts that ignore errors and send a request when they shouldn't.
Make sure both your server-side and client-side scripts are running in strict mode and lint them using ESLint. This will give you pretty good confidence that there are no typos.
Sometime it is becaseu of this let data = JSON.parse(this.response); so try to change it to
let data = JSON.parse(this.responseText);
I really did was change this.response to this.responseText

Vorto Dashboard not displaying the device model

while running the vorto dashboard im getting the following error
JWT expired, getting new Token Wed Aug 26 2020 07:38:56 GMT+0100 (BST)... StatusCodeError: 401 -
{"status":401,"error":"gateway:authentication.failed","message":"Multiple authentication
mechanisms were applicable but none succeeded.","description":"For a successful authentication
see the following suggestions: { The JSON Web Token is not valid. },
{ Please provide a valid JWT in the authorization header prefixed with 'Bearer ' }."
The contents of config.json is as follows
{
"client_id": "xxxxxxxxxxx",
"client_secret": "xxxxxxxxxxxx",
"scope": "xxxxxxxxxx",
"intervalMS": 10000
}
Tried with setting the contents of config.json as environment variables. Then also im getting same error. Screenshot of web front end on accessing localhost:8080 is attached
Tried with the following links Error running Vorto Dashboard for Bosch iot suite. But still its not working. Please help me in solving this issue
I have discussed the matter internally to Bosch (disclaimer: I am an employee).
After discussing with the Bosch Suite Auth team, here is a summary of what happened.
The Suite Auth team recently transitioned from Keycloack to Hydra for their authentication technology
The relevant bit here is that previously, the scopes passed to the token request were ignored
The Vorto Dashboard app had been passing the wrong key for the scope parameter all along, when requesting a token, but it was ignored
Now that this parameter is relevant, the (incorrect) notation was not failing to produce a token, but obtained one that was not suitable to authorize with Bosch IoT Things, because it did not contain the appropriate scope
In turn, fixing this key produces a token that successfully authorizes with Bosch IoT Things
If you're in a hurry, you can check out this branch with the fix (it's literally an 8 characters change set).
Otherwise, you can monitor this GitHub ticket for closure - I will close it when the fix is merged to the master branch of the Vorto Examples project.

Using d3 v5, in node console and WebStorm, can't get d3.csv() to work

I've spent the whole day trying to google and read examples of reading a data file with d3.csv() but don't find a really straight answer, not one that works. This should be simple.
I am using node version 8.10.0
I have done the following:
npm install d3
npm install fetch
npm install jsdom
I have a local file "data_stacked.csv"
group,Nitrogen,normal,stress
banana,12,1,13
poacee,6,6,33
sorgho,11,28,12
triticum,19,6,1
I started with this code:
var d3 = require("d3");
d3.csv("data_stacked.csv").then (function(data) {
console.log(data)
});
When it executes I get" "ReferenceError: fetch is not defined"
To make a long story short I went down all sorts of rabbit holes involving 'fetch", "jsdom", and a number of other things, none of which worked.
If I add the line
var jsdom = require("jsdom");
I get this error output:
/home/carl/WebstormProjects/node-project-2/node_modules/webidl-conversions/lib/index.js:357
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/carl/WebstormProjects/node-project-2/node_modules/jsdom/lib/jsdom/browser/Window.js:3:27)
I tried it with node, with WebStorm, and opening directly in a browser.
The long and the short of it is I just want to be able to get the data from a local CSV file from a javascript program run with node. I'm hoping to find a brief example of code that just works. Nothing I find on the googles seems to do that. If anyone can point me to an example that is a simple but complete piece of code (not a snippet omitting some needed context) I'd greatly appreciate it.
TIA
OK I'm answering my own question here since I understand this better now.
The d3.csv() call should be in the client-side javascript for instance in, or included, in index.html (or whatever hmtl page it's needed on).
If you specify a local path, for instance:
d3.csv("data.csv").then(
function(data) { ...});
the browser probably will complain (visible in its developer console) with something like "URL scheme must be http or https ..." - this is a security feature.
Easy work-around is to use the simple python server:
python -m SimpleHTTPServer <port> &
where is a port number not reserved for anything else, say maybe 3001, then in the browser address bar enter:
localhost:3001
On the other hand if you want to use nodejs, in your index.js file add the lines:
const dataPath = __dirname + '/data.csv';
app.get ('/data.csv', function(req, res) { res.sendFile(dataPath); });
The above assuming you've set up 'app' as an 'express' instance. Also it appears that the file path in the client side d3.csv() path should be '/data.csv' not just 'data.csv'

Appcelerator message = "JSON Parse error: Unexpected identifier \"undefined\"";

I am adding new features to an app I wrote last years and is working now ... I just port the code from Appcelerator (3.2...) to the Appcelerator Studio 5.2.0.GA SDK ... and I have spent 2 days trying to figure out why code that currently works on an app in the app store is not working in the SDK 5.2.0 environment
I keep getting the above error .. I am positive the url is correct and working
This line of code works now in the app in the store and in 3.1... but is not working in 5.2.0
var jsonObject = JSON.parse(this.responseText);
It gives the above error
"JSON Parse error: Unexpected identifier \"undefined\"";
I have read their site and searched for a solution ... Thanks
entire Block
Try one thing:
Open this site and put your response data in which you are getting error https://jsonformatter.curiousconcept.com
After parsing the same data on the above site, you can check whether the problem is really in your Titanium code or in your data.
Also check whether you are really getting any response data or not.
If it does not help, then please share some necessary source code
Thanks

Wirecloud FI-Ware Testbed compatibility

I was wondering if Wirecloud offers complete support for object storage with FI-WARE Testbed instead of Fi-lab. I have successfully integrated Wirecloud with Testbed and have developed a set of widgets that are able to upload/download files to specific containers in Fi-lab with success. However, the same widgets do not seem to work in Fi-lab, as i get an error 500 when trying to retrieve the auth tokens (also with the well known object-storage-test widget) containing the following response:
SyntaxError: Unexpected token
at Object.parse (native)
at create (/home/fiware/fi-ware-keystone-proxy/controllers/Token.js:343:25)
at callbacks (/home/fiware/fi-ware-keystone-proxy/node_modules/express/lib/router/index.js:164:37)
at param (/home/fiware/fi-ware-keystone-proxy/node_modules/express/lib/router/index.js:138:11)
at pass (/home/fiware/fi-ware-keystone-proxy/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/home/fiware/fi-ware-keystone-proxy/node_modules/express/lib/router/index.js:173:5)
at Object.router (/home/fiware/fi-ware-keystone-proxy/node_modules/express/lib/router/index.js:33:10)
at next (/home/fiware/fi-ware-keystone-proxy/node_modules/express/node_modules/connect/lib/proto.js:195:15)
at Object.handle (/home/fiware/fi-ware-keystone-proxy/server.js:31:5)
at next (/home/fiware/fi-ware-keystone-proxy/node_modules/express/node_modules/connect/lib/proto.js:195:15)
I noticed that the token provided in the beggining (to start the transaction) is
token: Object
id: "%fiware_token%"
Any idea regarding what might have gone wrong?
The WireCloud instance available at FI-WARE's testbed is always the latest stable version while the FI-LAB instance is currently outdated, we're working on updating it as soon as possible. One of the things that changes between those versions is the Object Storage API, so sorry for the inconvenience as you will not be able to use widgets/operators using the Object Storage in both environments.
Anyway, the response you were obtaining seems to indicate the object storage instance you are accessing is not working properly, so you will need to send an email to one of the available mail lists for getting help (fiware-testbed-help or fiware-lab-help) telling what is happening to you (remember to include your account information as there are several object storage nodes and ones can be up and the others down).
Regarding the strange request body:
"token": {
id: "%fiware_token%"
}
This behaviour is normal, as the WireCloud client code has no direct access to the IdM token of the user. It's the WireCloud's proxy which replaces the %fiware_token% pattern with the correct value.