I have a route that works when I use localhost:3000, but breaks when I use the live app on gcloud's app engine? - node.js

The route uses the DELETE method, which I was able to use in nodejs with the use of the method-override npm package. I can use curl for my GET and POST routes fine, but for the DELETE route in particular, when I change the url from http://localhost:3000/ to http://nameofapp.appspot.com/ in my cURL call, I get a "Error 400 (Bad Request)!!1" in return.
I looked at the route on the dashboard, and it's shown under "client errors" and it shows an error rate of 100% but doesn't give me any more information than that. It is always successful with localhost.
Any ideas??

Related

Node - Unable to Verify the First Certificate / UNABLE_TO_VERIFY_LEAF_SIGNATURE localhost

I have an ASP.NET Core 3.1 web app that I run on my local development machine. This app successfully runs. I can also successfully execute requests to it via Postman. I'm trying to run a test from a Node.js app. This app is using Axios to try to load one of the web pages. The request looks like this:
const result = await axios.get('https://localhost:5001/');
When this request runs, I receive the following error:
Error: unable to verify the first certificate
...
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
...
The fact that I can a) load the url in my browser and b) run the request from Postman leads me to believe there is a config issue with my Node app. I don't know if it's an issue with a) my axios request or b) some app configuration. Oddly, I receive the same error if I try to execute my request against http://localhost:5000/ (i.e. not over HTTPS).
I'm unsure how to resolve this issue though. How do I execute a request via Axios against a web app running on localhost?
You'll need to tell axios/node what signing authorities to trust (your browser and postman will already have several of those set up)
You do that by configuring the https agent in axios - have a look at this answer for an example : How to configure axios to use SSL certificate?
And here are instructions on how to get the bundle from the browser (you'll probably need to use a p7b/pfx or get all certs in the chain): https://medium.com/#menakajain/export-download-ssl-certificate-from-server-site-url-bcfc41ea46a2

axios network error with cors activated still returns error

the link to the code link
I am using axios and nodejs.
All routes work and give a response except one. which returns Network error.
that route is /api/ads/myads.
The route works on its own but when used with redux actions it doesn't
The network tab says that this request was blocked.
So I tried to add cors but that didn't solve the issue.
The file in question is .../actions/adActions this one is producing the error while others don't
I will be uploading the code in a minute
This turned out to be my adblocker thinking this was actual ads

Following a Twilio Tutorial to Record Phone Calls: Resulting in a 404 HTTP Error

I'm following this tutorial linked here which incorporates Twilio Programmable Voices and Express to record inbound phone calls. I followed the tutorial exactly, set up a ngrok public server, connected it to my http://localhost:3000, and I get the following output when I navigate to my ngrok link:
Cannot GET /
When I check ngrok in my terminal, it says "404 Not Found" for a GET (which is not in my code) and POST request. If I add a simple GET request to my code (such as "Hello World"), then in the browser, I see "Hello World" when I run my application. In the terminal, GET is able to succeed but POST still returns a "404 Not Found".
I've checked several other stack overflow questions, I've tried importing body-parser as recommended and adding these two lines:
const bodyParser = require('body-parser');
app.use(bodyParser.json());
For reference, my directory has a record.js file, package.json and package-lock.json files, and necessary node modules. In my Twilio Console, I did set up a web hook for my Twilio # to the ngrok link which looks like this: http://39b62a0c34b1.ngrok.io. To show my order of executions:
Run ./ngrok http 3000 in Mac Terminal
Run node record.js in VS Code terminal
Navigate to http://39b62a0c34b1.ngrok.io
Call my Twilio #
The voice message tells me that there's a problem with my application. I've checked the Twilio Debugger and I receive back a 11200 Error informing me that my ngrok link returned a "HTTP status code of 404".
I'm quite new to Node.js, Express, and Twilio, so any and all help is appreciated (please simplify your explanation)! I want to be a Developer Evangelist for Twilio someday so I'm more than prepared to make mistakes now to troubleshoot them in the future.
Twilio uses x-www-form-urlencoded, not JSON, for Webhhooks.
You will need to add Express middleware to parse urlencoded data out.
The 3rd Line:
// Body Parser Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
Where do I find the specifications for inbound HTTP requests to my server?
Let me know how it goes.
Still not clear why you are getting a 404 - Not Found. The app.post should kick in for POST operations. app.all for all operations. Are you using the /record path in your testing?

Connecting front-end and back-end with react and mongo DB - 404 error

I am trying to connect an app hosted in my localhost:3000 port. The back-end is on the localhost:8080 port (not a remote API but on my own PC. I downloaded a pre-created back-end api and linked the front-end to the back-end with MongoDB using an .env file.
The weird thing is that on MongoDB the connection looks ok, following the tutorial I am using. The backend and the front-end also look alrigh, however, I am unable to login with the form in the screenshot.The error I get when trying to login or create a new user is "xhr.js:178 POST http://localhost:3000/login 404 (Not Found)"
It was a bit hard to put the whole code here, so I am linking you to the front-end repo: https://github.com/manuelalonge/complex-app and the back-end repo: https://github.com/manuelalonge/back-end-api
I can understand the issue is most likely on the back-end but I could not understand where exactly. I tried to get back to the previous lessons in the tutorial but it still doesn't get solved.
Probably it is easier to solve this issue with a screenshare session, so if anybody would contact me I'll be grateful.
Screenshot --> [1]: https://i.stack.imgur.com/jVJzn.png
Your screenshot points to what's wrong. You're posting to localhost:3000, as you know this is the frontend webpack server.
You'll want to create an axios config file and set a base url to hit the correct endpoint.
const axiosInstance = axios.create({
baseURL: 'localhost:8080'
});
export default axiosInstance;
Also, please add some sort of file structure.

angular universal https problems

I have an angular universal app set up. I do POST requests on the server-side using localhost to pre-render my app and this works fine.
An example working url would be http://localhost:8000/api/get-info.
I've now put the app into production on an external url (apache server). I'm also using ssl.
Now when I try to do a POST request on the server-side to pre-render my app, I get back a response with status: 0, url: null (I'm assuming this means the connection was refused).
An example non-working url would be https://mywebsite.com/api/get-info.
What really stumps me is that when the app loads on the client, all HTTPS requests start working. So the problem is I cannot get the express server to send POST requests to my external url.
I've tested a post request on the server-side to a different website (twitter), and that seems to work fine as well. So i'm not entirely sure where I've gone wrong.
I already have CORS set to '*' as well.
Try using
http://localhost:8000/api/get-info
in production as well. Since your Angular app is rendered on the same server as your API is running, using localhost should just work fine. It doesn't matter if you are on an external URL.
I do something similar (its a GET but that shouldn't matter) with my translations:
if ( this.isServer ) {
translateLoader.setUrl( 'http://localhost:4000/assets/localization/' );
} else {
translateLoader.setUrl( 'assets/localization/' );
}
It works locally and in production (both server and client).
I just encountered this problem myself for two days. Please take a look at my comment on https://github.com/angular/universal/issues/856#issuecomment-426254727.
Basically what I did was I did a conditional check in Angular to see if the APP is running in browser or in server (rendered by Angular Universal), and change my API endpoint to actual IP in https or localhost in http accordingly. Also in my Nginx setting, I only redirect incoming request from browser to https by checking if the server_name is localhost.
Hope it helps!

Resources