website not opening in first time shared link in browser angular 8 and nginx - node.js

bhaskarhindi.com id an angualr8 front end and Nginx server hosted in AWS instance using nodejs Redis API call to fetch data.
But after deploying and using hash the first time in the browser it is not opening showing 404 error.
But after a hard refresh or multiple time click it's opeing.
Any solution i have tried index.html aot and hashed build but not working.

404 is shown by the server itself, when it tries to find the route you have passed in the URL (as the server doesn't have access to that route, but Angular has).
You need to make sure that the server redirects all the 404 requests to the index.html of the Angular application. Only then Angular can pick up and show the pages accordingly.
Read through this: https://angular.io/guide/deployment#server-configuration for more information.

Related

ERR_CONNECTION_REFUSED on EC2 public DNS caused by HTTPS

I'm developing a web app using Next.js that is, in the end, served by a custom Express.js server. I'm trying to deploy this app on EC2 and access it but I'm getting ERR_CONNECTION_REFUSED errors.
I'm accessing the app over HTTP using the public DNS of my instance (http://ec2-PUBLIC_IPV4_ADDRESS.compute-1.amazonaws.com/) which works fine, the index.html then needs to load other files (e.g.: .js or .css files), but tried to load them over HTTPS (https://ec2-PUBLIC_IPV4_ADDRESS.compute-1.amazonaws.com/style.css). In the network tab of the developer tool of Chrome, I get one request that is succesful and other assets that fail with net::ERR_CONNECTION_REFUSED.
I was wondering if there is a config either on my EC2 instance, on my Express server or even on Next.js that needs to be modified to make sure that the connection is not upgraded to HTTPS.
I would prefer to find a solution that doesn't involve setting up a domain for early testing purposes.
Thanks in advance.

loading socket.io-client.socket.io.js fails when using ssl

I have developed a node js application which works fine as long as use http. Now I need to upgrade the code too be able to work ssl and I am having problems to load the socket.io-client/socket.io.js file. (The rest is working fine. I installed the certificates and the server works well)
Firefox fails with the following message: Blocked loading mixed active content "http://"url"/socket.io/?EIO=3&transport=polling&t=NX-uS5E". which is weird because the link states a http request.
Chrome fails with this message: socket.io.js:3511 Mixed Content: The page at 'https://"url"?' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://"url"/socket.io/?EIO=3&transport=polling&t=NX-s_OB'. This request has been blocked; the content must be served over HTTPS.
It seems that socket.io-client is trying to load a resource using http instead of https. Is that possible?
How can I correct this? Any idea?
I have been searching the web for two days noow and I have not come to any indication of someone else having this issue
Ok, after letting it go for the evening and having a good rest I checked my whole code again and found the error!
I had one obfuscated code line where I was using a http request instead of a https one. I had to correct this on both, the server and the client side.
I also had to include the port number on each of the calls and force the socket on the client side to use polling instead of websockets by adding the option "transports: ['polling']"

XMLHttpRequest cannot load http://localhost:5000/api/users/signup due to access control checks

I am using nodeJS and expressJS for backend and ReactJS for frontend of my application. Everything works fine when run locally on my computer. However, I recently have tried to deploy the app using Heroku. The app successfully launches at the given link from Heroku but then whenever I try to sign in/sign up I'm always thrown an error from the backend. The error is as follows when I am using Safari and Google Chrome respectively:
I have already enabled cors on my expressJS server, what is the likely cause of the issue?
It looks like your ReactJS code has the url http://localhost:5000/ hard coded in it somewhere. If your same Heroku instance serves the ReactJS and provides your API endpoints, then you should consider using
/api/users/signup
for the URL of your API endpoint instead of
http://localhost:5000/api/users/signup
This wrong URL shows up as an access control issue because browsers block external pages served by https to use localhost APIs. Because cybercreeps.

Socket.io.js can't be found (404)

I've developed a small chat application with Socket.io and Express, currently deployed on my droplet at digital ocean. You can see it live at https://keleheart.com/chatapp. It currently doesn't work because the server is giving back a 404 for the chatapp/socket.io/socket.io.js script I have at the bottom of my html file, should be able to see that when you visit the site and hit f12
I've been through a few fixes already that were popular on here such as This one and this one and I've even tried changing the script from local to a CDN as depicted here , and the CDN seems to work better,(still gives the 404 but it then no longer says io isn't defined??) but it still doesn't produce the output I need.
You are able to review my repo on my Github Page for this as well, there's just the index.html file for the client and then the chatApp.js for the server. The error is coming from my html file but all the fixes have told me to manipulate my package.json, server variables, and nothing has worked so far. My server still cannot find chatapp/socket.io/socket.io.js
Have you tried creating the /socket.io folder next to index.html, and putting a copy of socket.io.js inside of that? That has always worked for me, but you might have to hunt through the node_modules folder to get the file. This always fixed it for me.
And of course, be sure to actually serve the file using express's static method.
Your browser is giving you the correct error message. Since /socket.io/socket.io.js does not exist on the server, the browser displays the server's 404 message.

angularjs - routes not working when typed

Could anyone explain why when I click on a link my angular views get shown fine but when I type in an address into the address bar in the browser (which is the same as where the links that work point to) such as localhost:8080/login I get a Cannot GET /login message.
My routes are set up in Angular and I'm using Node and Express 3 on the back-end.
What silly mistake am I making?
Most likely you're getting angular and your webserver mixed up.
The webserver probably doesn't know to server your angular base page when the /login URL is entered. You need a catch-all handler on your nodejs server.

Resources