Javascript require() method

Javascript require() method

Anonymous
Not applicable
1,130 Views
9 Replies
Message 1 of 10

Javascript require() method

Anonymous
Not applicable

hi experts

 

i'm trying to make an HTTPS call from Fusion to my AWS server.  The call involves:

var https = require()

 

but this method is not recognized by Fusion. 

 

Further searching, require() method is a part of requirejs which has to be installed in node.js.

 

in short, have you tried calling out to HTTPS from Fusion script ?  and how to do it?

 

thanks

KP

0 Likes
1,131 Views
9 Replies
Replies (9)
Message 2 of 10

tony.mandatori
Autodesk
Autodesk

I have used require() before in node.js to load other code code and libraries (like log4js and fs).

 

There is a port for client side loading of files.  But the javascript in Fusion is server side only.

 

require() is not part of standard JavaScript, it is built into Node.js to load modules.

 

 

 

 

0 Likes
Message 3 of 10

tony.mandatori
Autodesk
Autodesk

You should be able to make HTTPS requests using the same method we use for the Octopart integration.

 

        var xhr = new XMLHttpRequest();
       
        xhr.open('GET', url);
        xhr.setRequestHeader('Content-Type', 'application/json');
        xhr.setRequestHeader('Accept', 'application/json');
        xhr.send();

 

i haven't tried this.  Let us know if it works.

0 Likes
Message 4 of 10

Anonymous
Not applicable

thanks Tony

 

I have tried var xhr = new XMLHttpRequest(); before posting here.  It's only good for http web call.  My web server is ssl enabled

0 Likes
Message 5 of 10

tony.mandatori
Autodesk
Autodesk

From what I see online, it should work with HTTPS as well.

 

Again, I haven't tried this.

0 Likes
Message 6 of 10

Anonymous
Not applicable

Depending on your authentication method you may be able to set additional
request headers in this manner

xhr.setRequestHeader("Authorization","Basic XXXXXX1XXXXX2XXXXX3XXXXX6==");

The "XXXXX" is the base 64 encoded authorization credentials.

 

Michael Pares

0 Likes
Message 7 of 10

tony.mandatori
Autodesk
Autodesk
Just be careful because the Base64 encoding is not encrypting... so people can get the password from the string.
0 Likes
Message 8 of 10

Anonymous
Not applicable

You are right.  It can be decoded just as easily as it is encoded. 

0 Likes
Message 9 of 10

Anonymous
Not applicable

i have an self signed certificate on the server. this kind of cert always prompt user to trust it in the browser and in code.  how do you ignore its warning in the script

0 Likes
Message 10 of 10

Anonymous
Not applicable

I did a little search and find that a lot of people have asked that question before and come up short when it comes to javascript.

 

http://stackoverflow.com/questions/4490723/javascript-xmlhttprequest-ignore-invalid-ssl-certificate

 

Most suggest that you need a valid cert.

0 Likes