API Gateway JavaScript SDK timing out - javascript

I've created an API in API Gateway which calls a lambda function to query my RDS database and return the query results as JSON. I'm trying to call my api from JavaScript using the following code but all I'm getting in the console of the browser is 'GET https://myurl/v1/it-requests net::ERR_TIMED_OUT'. But when I run call the API from the URL it returns the query result? My JavaScript is below.
var apigClient = apigClientFactory.newClient({
apiKey: 'myApiKey',
});
var params = {
};
var body = {
};
apigClient.itRequestsGet(params, body)
.then(function(result){
console.log = JSON.stringify(result);
}).catch(function(result){
console.log = "Sorry, API Gateway is not responding";
});
<script type="text/javascript" src="lib/axios/dist/axios.standalone.js"></script>
<script type="text/javascript" src="lib/CryptoJS/rollups/hmac-sha256.js"></script>
<script type="text/javascript" src="lib/CryptoJS/rollups/sha256.js"></script>
<script type="text/javascript" src="lib/CryptoJS/components/hmac.js"></script>
<script type="text/javascript" src="lib/CryptoJS/components/enc-base64.js"></script>
<script type="text/javascript" src="lib/url-template/url-template.js"></script>
<script type="text/javascript" src="lib/apiGatewayCore/sigV4Client.js"></script>
<script type="text/javascript" src="lib/apiGatewayCore/apiGatewayClient.js"></script>
<script type="text/javascript" src="lib/apiGatewayCore/simpleHttpClient.js"></script>
<script type="text/javascript" src="lib/apiGatewayCore/utils.js"></script>
<script type="text/javascript" src="apigClient.js"></script>

Browser's have default timeouts see this you can return 202 initially and keep the connection alive while u r doing stuff, then once your processing is done end the connection.
for example:
res.status(200);
res.type('application/json');
res.write(' ');
res.flush();
const writeInterval = setInterval(() => {
res.write(' ');
res.flush();
}, 15000);
After processing is done:
res.end(JSON.stringify({
success: 1
//blah...
}));

Related

Outputting Firebase database data to webpage

I am trying to output all the data from my Firebase Database to a blank webpage. I currently have it printing out in the chrome console using the code below.
ref.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (error) {
console.log("Error: " + error.code);
});
Instead of it printing to the console I want it to print to the actual webpage itself. Struggling since there is not much documentation around Firebase itself.
Here is my entire code for the near blank html page im trying to output the Firebase database data to. I have also included a picture of the structure of my Firebase database.Here
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src = "https://www.gstatic.com/firebasejs/4.6.2/firebase-app.js">
</script>
<script src = "https://www.gstatic.com/firebasejs/4.6.2/firebase-auth.js">
</script>
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-database.js">
</script>
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" href="img/membrain.ico">
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
<script>
const config = {
.........
};
firebase.initializeApp(config);
</script>
</head>
<body>
<h1>Firebase Database</h1>
<script>
var ref = firebase.database().ref();
ref.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (error) {
console.log("Error: " + error.code);
});
</script>
</body>
</html>

Youtube api sample code Can't run

I am playing with google api. This code is from codeacademy.
Here is HTML
<!DOCTYPE html>
<html>
<head>
<script src="app.js" type="text/javascript"></script>
<script src="https://apis.google.com/js/client.js?onload=onClientLoad" type="text/javascript"></script>
</head>
<body>
<pre id="response"></pre>
</body>
</html>
Here is javascript:
// Your use of the YouTube API must comply with the Terms of Service:
// https://developers.google.com/youtube/terms
// Helper function to display JavaScript value on HTML page.
function showResponse(response) {
var responseString = JSON.stringify(response, '', 2);
document.getElementById('response').innerHTML += responseString;
}
// Called automatically when JavaScript client library is loaded.
function onClientLoad() {
gapi.client.load('youtube', 'v3', onYouTubeApiLoad);
}
// Called automatically when YouTube API interface is loaded (see line 9).
function onYouTubeApiLoad() {
console.log("onYouTubeApiLoad");
// This API key is intended for use only in this lesson.
gapi.client.setApiKey('1111111111AIzaSyBenRS7G9WPDylh2JAXOeD2uLsao6VW2QY');
search();
}
function search() {
// Use the JavaScript client library to create a search.list() API call.
var request = gapi.client.youtube.search.list({
part: 'snippet',
q: 'surfboards'
});
// Send the request to the API server,
// and invoke onSearchRepsonse() with the response.
request.execute(onSearchResponse);
}
// Called automatically with the response of the YouTube API request.
function onSearchResponse(response) {
showResponse(response);
}
It's suppose to work fine. But I don't know why - function onYouTubeApiLoad() - is never called. What is wrong? Can't figure out.

Linkedin shows 403 forbidden error in java script api

I am trying to search people with company name but it displays in console as
GET https://api.linkedin.com/v1/people-search:(num-results,people:(first-name,last-name,distance))?company-name=infosys 403 (Forbidden) xdrpc.html?v=0.0.2000-RC8.35784-1413:1651
My Code :
<html>
<head>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: --api-key-here--
onLoad: onLinkedInLoad
authorize: true
</script>
<script type="text/javascript">
function onLinkedInLoad() {
alert("authenticating..");
// Listen for an auth event to occur
IN.Event.on(IN, "auth", onLinkedInAuth);
}
function onLinkedInAuth() {
IN.API.PeopleSearch()
.fields("firstName", "lastName", "distance")
.params({"company-name":"infosys"})
.result(displayPeopleSearch)
.error();
}
function displayPeopleSearch(peopleSearch){
var peopleSearchDiv = document.getElementById("peoplesearch");
var members = peopleSearch.people.values;
for (var member in members) {
// but inside the loop, everything is the same
// extract the title from the members first position
peopleSearchDiv.innerHTML += "<p>" + members[member].firstName + " " + members[member].lastName + " is a " + members[member].positions.values[0].title + ".</p>";
}
}
</script>
</head>
<!-- need to be logged in to use Search; if not, offer a login button -->
<script type="IN/Login"></script>
<body>
</body>
</html>
Found after a big battle,Linked IN has created vetted API access to people search only developers registered to that process can Access people search function

Running javascript after Ajax call

I've been tasked with removing all Telerik controls from our website. I'm not that good with javascript, so this is a great learning experience for me. Most of the controls are easy to understand and fairly easy to replace, but I'm stuck on one. I need to replace the RadScriptBlock in the following code:
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript" src="<%=ConfigurationHandler.getStaticContentBaseURL(Request)%>js/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="<%=ConfigurationHandler.getStaticContentBaseURL(Request)%>js/jquery-migrate-1.1.0.min.js" ></script>
<script type="text/javascript" src="<%=ConfigurationHandler.getStaticContentBaseURL(Request)%>js/jquery.json-2.4.min.js"></script>
<script type="text/javascript" src="<%=ConfigurationHandler.getStaticContentBaseURL(Request)%>js/Portal/main.js" ></script>
<script type="text/javascript" src="<%=ConfigurationHandler.getStaticContentBaseURL(Request)%>js/Portal/popup.js" ></script>
<script type="text/javascript" src="<%=ConfigurationHandler.getStaticContentBaseURL(Request)%>js/SeoTracking.js" ></script>
Based on everything I've read, I think I need to use the following, but I'm at a total loss as to how. Any help/suggestions/resource would be greatly appreciated!!!
new Ajax.Request('/your/url', {
onSuccess: function(response) {
// Handle the response content...
}
});
So this ended up being the fix...
<script type="text/javascript" src="http://localhost:44344/js/jquery-1.9.0.min.js">
</script>
<script>
$.ajax({
url: 'AjaxOrderStepServer.aspx',
success: function () {
debugger;
var baseurl = ConfigurationHandler.getStaticContentBaseURL(Request);
var url = baseurl + "/js/jquery-migrate-1.1.0.min.js";
$.getScript(url);
url = baseurl + "/js/jquery.json-2.4.min.js";
$.getScript(url);
url = baseurl + "/js/Portal/main.js";
$.getScript(url);
url = baseurl + "/js/Portal/popup.js";
$.getScript(url);
url = baseurl + "/js/SeoTracking.js";
$.getScript(url);
}
});

XMPP - Example chapter 3 "Professional XMPP Programming with JavaScript and jQuery" doens't work

I am just new to XMPP, and I am making the first "HELLO" code. Please take your time look at the following code (the .zip is at the end of this topic):
<html>
<head>
<title>Hello - Chapter 3</title>
<style type="text/css">
body {
font-family: Helvetica;
}
h1 {
text-align: center;
}
.hidden {
display: none;
}
#log {
padding: 10px;
}
</style>
<script language="javascript" type="text/javascript" src="scripts/jQuery.js"></script>
<script language="javascript" type="text/javascript" src="scripts/jQueryUI.js"></script>
<script language="javascript" type="text/javascript" src="scripts/strophe.js"></script>
<script language="javascript" type="text/javascript" src="scripts/flXHR.js"></script>
<script language="javascript" type="text/javascript" src="scripts/strophe.flxhr.js"></script>
<link rel="stylesheet" href="hello.css"></link>
<script language="javascript" type="text/javascript">
var Hello = {
connection: null,
log: function(msg) {
$("#log").append("<p>" + msg + "</p>");
}
};
$(document).ready(function() {
$("#login_dialog").dialog({
autoOpen: true,
draggable: false,
modal: true,
title: "Connect to XMPP",
buttons: {
"Connect": function() {
$(document).trigger("connect", {
jid: $("#jid").val(),
password: $("#password").val()
});
$("#password").val("");
$(this).dialog("close");
}
}
});
$(document).bind("connect", function(ev, data) {
var conn = new Strophe.Connection("http://bosh.metajack.im:5280/xmpp-httpbind");
conn.connect(data.jid, data.password, function(status) {
if (status === Strophe.Status.CONNECTED) {
$(document).trigger("connected");
} else if (status === Strophe.Status.DISCONNECTED) {
$(document).trigger("disconnected");
}
});
Hello.connection = conn;
});
$(document).bind("connected", function() {
// Inform the user
Hello.log("Connection established");
});
$(document).bind("disconnected", function() {
Hello.log("Connection terminated.");
// Remove dead connection object
Hello.connection = null;
});
});
</script>
</head>
<body>
<h1>Hello</h1>
<div id="log"></div>
<!-- Login dialog -->
<div id="login_dialog" class="hidden">
<label>JID:</label><input type="text" id="jid">
<label>Pwd:</label><input type="password" id="password">
</div>
</body>
</html>
According to the document, and the code, it must either say "Connection establised" or "Connection terminated". But it doesn't. I tried to put alert("It runs to here!"); in every line of the code, and it still alert(). It doesn't alert anymore when I put it in bind("connected") and bind("disconnect"). So I guess the code can not run to there. I've never done it before, and there is rarely documents about this, so I don't know what to do now.
Question: Could you guys please take a look at it, and tell me what was wrong? I myself is still working on debugging it!
Extra information: These are what is in my web folder (I am afraid of missing javascript framework files). All js files are latest version.
index.html
scripts/
jQuery.js
jQueryUI.js
strophe.js
flensed.js
flXHR.js
flXHR.swf
flXHR.vbs
swfobject.js
updateplayer.swf
checkplayer.js
css/
Not important...
Here are my code, please take time to view it: http://xx3004.kodingen.com/XMPP
I would appreciate any view of help.
[x]
your code is alright,
the problem is in the URL provided to make the connection using Strophe.
var conn = new Strophe.Connection("http://bosh.metajack.im:5280/xmpp-httpbind");
Try to find the location of the server, otherwise install an xmpp server(vysper), locally on your machine, and change the URL as http://localhost:8080/bosh/
Also try to comment the flxhr inclusion.
If you are running Openfire on your localhost make sure
bosh_service_url = 'http://127.0.0.1:7070/http-bind/'
ie
var conn = new Strophe.Connection("http://127.0.0.1:7070/http-bind/");
And if you are running ejabberd on your localhost make sure
bosh_service_url = "http://127.0.0.1:5222/http-bind/"

Categories