Angular8: Call localhost Rest Api services - django

I developed my web application with Angular 8. The backend is a rest api that I developed with django rest framework and it's viewed just in the localhost. I tested it and it works fine. For example the service http://127.0.0.1:8000/api/devices gives a list of devices. It gives a good results if I test it with browser or curl command.
I'm calling this service from my angular app. I executed the angular app with the command: ng serve --host 0.0.0.0 --port 4201
If I open the web application in the browser with http://127.0.0.1:4201/api/devices the service /api/devices is well called and I get the list of devices in my web page. but if I open the web application with my LAN IP address like that http://192.168.1.59:4201/api/devices, so I get HTTP 400 bad request error in my console.
And the same error is shown in django server traces: GET /api/devices/ HTTP/1.1" 400 26
After some searches in the internet I concluded that this error is frequently coming from angular app especially the proxy:
my proxy config file proxy.config.json is:
{
"/api" : {
"target": "http://localhost:8000",
"secure": false
}
}
I mad other searches and I found an answer to similar question Angular 6 call localhost API and after following the angular doc https://angular.io/guide/build in "Proxying to a backend server" section then I modified my proxy config file to:
{
"/api": {
"target": "http://localhost:8000",
"secure": false,
"pathRewrite": {
"^/api": ""
}
}
}
Has any one an idea what can be the main cause of the issue? and how I can fix it?

ng serve --host 0.0.0.0 --port 4201 --disable-host-check

Related

Dev Proxy from webpack dev server to flask backend connection refused

I've been working on a react app and I wanted to get hot re-loading going so I set up a webpack dev server. It's working great. It runs on localhost:8080 and the hot re-loading works perfectly.
Great, now I just need to set up a proxy to route requests from 8080 to my flask server running on 5000 right?
Cool so I added a proxy field to my webpack.config.js
27 devServer: {
28 static: './static/dist',
29 proxy: {
30 '/': 'http://localhost:5000',
31 secure:false,
32 }
33 },
But when I re-run npm run start
"start": "webpack serve --open --mode=development"
I get all of these connection refused errors. My flask is up and running fine and I can query the api routes directly and have data be returned.
[webpack-dev-server] [HPM] Error occurred while proxying request localhost:8080/all_users to http://localhost:5000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
I followed the URL and the only advice there was that this error usually occurs when the external system is down. Since mine isn't, I'm pretty confused.
Any help would be greatly appreciated.
I have no idea why but changing 'http://localhost:5000' to 'http://127.0.0.1:5000' solved my problem.
If anyone knows I'd still be curious why this fixed it. I can go to 'http://localhost:5000' in my browser and query my backend just fine.

Connecting to Google Cloud PostgresSQL Server for local Strapi Application

I have a Google cloud Postgres server set up, and under the production environment I am able to connect to the server correctly. However, when I try to connect to the same cloud server in my local server, it doesn't seem to work. Here's the configuration for my database.js
module.exports = ({ env }) => {
return {
defaultConnection: "default",
connections: {
default: {
connector: "bookshelf",
settings: {
client: "postgres",
host: `/cloudsql/${env("INSTANCE_CONNECTION_NAME")}`,
database: env("DATABASE_NAME"),
username: env("DATABASE_USERNAME"),
password: env("DATABASE_PASSWORD"),
},
options: {},
},
},
};
};
I also have the app.yaml set up as normal. I have also created the .env file to store the relevant env information.
The error I am getting is
error Error: connect ENOENT /cloudsql/my-app-286221:us-central1:blm-resources/.s.PGSQL.5432
Does Strapi in local development support connection to cloud database? Or am I doing something wrong here.
This shouldn’t be a strapi issue. First you need to have an access from outside to google cloud postgres database. I’m not familiar with google cloud services, but from documentation there seem to be a couple of things to do to grant access to database.
More info from documentation:
https://cloud.google.com/sql/docs/postgres/connect-external-app#appaccessIP
Basically you grant access for connection from outside and then you add that connection information to your strapi config file.
I noticed your host: is not pointing to http:// or https:// but to some google server’s local address.

This site can't provide a secure connection ERR_SLL_PROTOCOL ERROR

I have a google appengine project running in localhost. Everything works fine until i go to the 'login' page. When i go there i get the following error:
This site can’t provide a secure connection 127.0.0.1 sent an invalid response.
Try running Windows Network Diagnostics.
ERR_SSL_PROTOCOL_ERROR
the appengine command i use to run the project is dev_appserver.py" --host 127.0.0.1 . This is run pycharm. This only occurs in the 'login' endpoint and no other endpoint.
The console error i get is:
default: "GET /signin HTTP/1.1" 301 -
to connect over HTTPS you need a valid SSL certificate on your server here is you local server as I understand from the message. you can get a certificate for your local server but I don't think it's worth the trouble while working locally. On the other hand when you deploy to Google App Engine, you get SSL certificate automatically and it's managed by Google, that's why your code works without any problem in the deployment.

Curl is working on machine but not on web browser

I created a simple nodejs app on the aws-ec2 server following the instructions. The code is:
#!/usr/bin/env nodejs
var http = require('http');
http.createServer(function (req, res)
{
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080, '138.68.244.XXX');
//138.68.244.XXX is the IP of my ec2 server
console.log('Server running at http://localhost:8080/');
After I started the app by the command: node hello.js
I got output:
Server running at http://localhost:8080/
I was able to curl the URL:
curl http://138.68.244.XXX:8080
to get “Hello World” on the server itself, however, when I tried:
http://138.68.244.XXX:8080
in a browser, I got:
ERRCONNECTIONTIMED_OUT
Please help,
Thank you!
Check this FAQ entry (how to open a port on an instance with a public IP). As port 8080 is not a standard HTTP port, you probably need to update the security group and ACL.

Disable Authentication in SAP Cloud Foundry App

I would like to disable login on my SAP Cloud Foundry app. Here is my xs-app.json
{
"authenticationMethod": "route",
"routes": [
{
"source": "/",
"target": "/",
"destination": "nodeBackend1",
"csrfProtection": false,
"authenticationType": "none"
}
]
}
And manifest.yml:
---
applications:
- name: appnode-demo
host: appnode-demo-pxxxxtrial
buildpack: https://github.com/cloudfoundry/nodejs-buildpack.git
memory: 128M
services:
- xsuaanode-demo
- connectivity-demo-lite
- destinationnode-demo-lite
I got this error message from the log file when accessing the page url (https://appnode-demo-pxxxxtrial.cfapps.eu10.hana.ondemand.com/)
msg":"GET request to /nodeBackend1 completed with status 500 - Error
while retrieving destination nodeBackend1 from destination service.
HTTP status code: 400"}
If I changed the authenticationType on xs-app.json to basic, it is working fine (I need to enter my credential).
nodeBackend1 is a simple Nodejs http server app running on-premise (on my machine) connected to SAP Cloud Foundry with SAP Cloud Connector.
How to disable the authentication so I can access the page without entering my credential (make it public) ?