Connecting to Google Cloud PostgresSQL Server for local Strapi Application - google-cloud-platform

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.

Related

I can't connect to postgresql database in deployment

Hello I just want to deploy my django project in python anywhere .... and when I run the command python manage.py migrate
it shows this error message django.db.utils.OperationalError: connection to server at "<Host name>" (<IP address>), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?
I think that the problem in python anywhere because when I connect to the server in pgadmin using the same info in the settings.py file I don't get any error messages and you have to know that I am using neon.tech for my postgresql database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<the database>',
'USER':'<User>',
'PASSWORD':'<Password>',
'HOST':'<Host>',
'PORT':5432,
}
}
and I am sure that all information is right because I used it to connect to the server in pgadmin in my local machiene
If you are having trouble connecting to a PostgreSQL database in a deployment environment, there are a few things you can check:
Verify that the database is running: Make sure that the PostgreSQL database is running and accessible from the deployment environment. You can check this by attempting to connect to the database using the 'psql' command-line tool.
Check the connection settings: Ensure that the connection settings in your deployment configuration are correct, including the database host, port, database name, user, and password.
Check firewall settings: If you are connecting to a remote PostgreSQL database, ensure that the necessary firewall ports are open to allow incoming connections to the database server.
Check for network issues: Check for any network issues that may be preventing the deployment environment from connecting to the database. For example, if you are deploying to a virtual private cloud, ensure that the network settings are configured correctly.
Check for authentication issues: Make sure that the user and password specified in the connection settings have the necessary permissions to access the database.
Check logs for errors: Check the logs for any error messages that may indicate the cause of the connection issue.
By investigating the above points, you should be able to narrow down the cause of the connection issue and take the necessary steps to resolve it.

Django development server not accessible via Cypress E2E testing

I use django-tenants for multitenancy. I use subdomains for each tenant and have a test tenant set up with a schema_name=demo.
When running python manage.py runserver in local development, the server is accessible at http://demo.localhost:8000.
However, when configuring cypress to use the local server (via Chrome E2E), it does not resolve the server. I have confirmed that the server is running and accessible from a normal instance of
Chrome.
My cypress config:
module.exports = defineConfig({
projectId: '4dofbo',
e2e: {
baseUrl: 'http://demo.localhost:8000',
},
});
What could be causing this?

deploy nuxtjs application to GCP, but it gives server error?

I'm new to GCP (google cloud platform) I'm facing this problem, Backend dev created an Apache server on gcp, and then I cloned my repo on the server through VM, build it and then deployed it after following countless tutorials.. but while deploying it gives
Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.
when i go to the generated link which is https://vetution.oa.r.appspot.com/ it gives server error, I've searched a lot but I failed.
Have I done something wrong or the app.yaml file should have different configurations.
anyway here it is
runtime: nodejs12
instance_class: F2
handlers:
- url: /_nuxt
static_dir: .nuxt/dist/client
secure: always
- url: /(.*\.(gif|png|jpg|ico|txt))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|ico|txt)$
secure: always
- url: /.*
script: auto
secure: always
env_variables:
HOST: '0.0.0.0'
NODE_ENV: 'production'
And It gives me this error on deploying now
please, Help me I'm very frustrated.
The error states that, your app failed to start because it's not listening to a port as you may not have configure it to your app. This topic is answered on this Stackoverflow thread.
You mentioned that you followed countless tutorials, it is possible that you are using Cloud Run and App Engine interchangeably, which are 2 separate serverless products. Please evaluate on your end which platform is right for your app and use case.
Currently, there is not much debugging info to your question but either way, make sure that you configure your app's port to listen to incoming request/s, it can be port 8080 or can be any of your choice. Also, check your GCP logs, backend issues and server errors can be seen and monitored by simply looking at the logs for App Engine or Cloud Run.
Check Cloud Run configuring the container ports, for port configuration.

Angular8: Call localhost Rest Api services

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

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) ?