Django development server not accessible via Cypress E2E testing - django

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?

Related

Axios with django server on localhost

Trying to access django server on localhost from my react native app. All I get is Network Error, which doesn't say much. Tried changing info.plist file as suggested in other answers on stack, tried changing firewall settings and so on.
The thing that worked and solved all my problems was changing the url on axios to my local ip and running django server with command: python manage.py runserver 0.0.0.0 which to my understanding will accept any connection to the server.

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.

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

How can I connect to Django development server on Codenvy?

I'm currently testing Django on Codenvy but I have difficulties to find out how to connect to the build-in development server of Django.
I added a server in the Workspace configuration with port 8000 and http protocole.
I added the following in the run command of Codenvy's project :
Commande line :
cd ${current.project.path} && python manage.py runserver
Preview :
http://${server.port.8000}
The run prompt provide me a url : http://nodexx.codenvy.io:xxxxx
Going to this URL print a message : ERR_CONNECTION_REFUSED
I'm very new to all of this. Do you know what is missing ?
Django dev server by default accepts connections only from localhost. In order to access it from another machine, start runserver by binding it with an IP, or 0 for the app to be accessed from everywhere.
python manage.py runserver 0:8000
The above command runs the server in 8000 port, binding the network to 0.0.0.0, which means the app can be accessed from anywhere

Django - how to run it on a production server?

I am new to Django Project. I have my app moved to my production server and I have it run:
$ python manage.py runserver
>>> Starting gulp watch
>>> gulp watch gulp process on pid 30427
Validating models...
0 errors found
May 18, 2017 - 15:57:08
Django version 1.5.12, using settings 'website.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
But it is a production server with an IP, eg: 119.237.27.131
So it can't be running at http://127.0.0.1:8000/
Then what should I do so that the app is running on http://119.237.27.131:8000/ instead?
Any ideas?
Btw, where is 'website.settings'?
EDIT:
When I check the app at http://119.237.27.131:8000/
I get this error:
This site can’t be reached
119.237.27.131 refused to connect.
If you start the development server without any parameters, the server will start at localhost:8000, but it can't be accessed from outside the machine. To allow that, you should start the server like this:
python manage.py runserver 0.0.0.0:8000
That will allow you to connect from another machine, on the machine's IP address, like http://119.237.27.131:8000/
A word of warning: the development server is not a production-ready server. You should use a WSGI server like Gunicorn or another tool to serve your application. Do not use the development server in a production setting, it's not safe!! Read more about that here.