I’m doing the Stock Price Checker Project on Glitch. I am on one of the first requirements:
I can GET /api/stock-prices with form data containing a Nasdaq stock ticker and receive back an object stockData.
Something very strange happens that I cannot fix. I am using the boilerplate code for this project. And in api.js I have this GET route:
app.route('/api/stock-prices')
.get(function (req, res)
{
console.log("we made it to get")
})
Now this works fine, but then I add this code to do an https request to a different site it in an attempt to get stock info as per the project’s instructions:
app.route('/api/stock-prices')
.get(function (req, res)
{
console.log("we made it to get")
var ticker = req.query.stock
if (ticker.length)
{
console.log("we got the ticker")
//Create the https request
var path = "v1/stock/" + ticker + "/quote"
var options = {
host: "repeated-alpaca.glitch.me",
path: path,
method: "GET",
headers: {}
};
var httpsRequest = https.request(options, function (res)
{
var responseString = "";
res.on("data", function (data) {
responseString += data;
// save all the data from response
});
res.on("end", function () {
console.log(responseString);
// print to console when response ends
});
});
httpsRequest.on('error', (error) => {
console.log(error)
})
httpsRequest.end();
}
});
Now for all I know this code is completely wrong and I did initially get some sort of errors with it. But here is the fatal problem. My express app now permanently cuts off all request paths no matter what I do. I have deleted all this extra code that I put in and my request’s path still stays permanetly cut off. What I mean is that before I put in this extra code, my request path would look like this:
/api/stock-prices?stock=testname
But permanently after putting in the code, even after I deleted it, my requests path always look like this:
/?stock=sdf
So it’s always directing me back to the home page now. I am utterly stumped how to fix this. I’m worried it’s an error with Glitch and there’s no way to fix it. Does anyone have any ideas.