I am developing a website using django rest framework and react. And I transferred from the test VM to the timeweb cloud virtual cloud and ran into the problem that when connecting to the site, the site starts without information from the postgres database. And also when starting the react web server.the js command "npm run start" outputs an error in browsers on remote client computers:
JSON.parse: unexpected character at line 1 column 1 of the JSON data
I think this is due to the fact that there is no connection to the database server in postgresql. But, I've already tried adding addresses to ALLOWED HOSTS. I changed both the database and Django. P.S. The username, passwords and addresses are not real.
$ cat node_modules/react-scripts/config/webpackDevServer.config.js
...
// want to allow setting the allowedHosts manually for more complex setups
allowedHosts: disableFirewall ? 'all' : [allowedHost],
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': '*',
'Access-Control-Allow-Headers': '*',
},
allowedHosts: [
// Ваш список разрешенных хостов здесь
'localhost',
'127.0.0.1',
'IPADDR1'
],
...
$ cat settings.py
...
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'IPADDR1', 'HOST1']
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'BASE',
'USER': 'USER',
'PASSWORD': 'PASSWORD',
'HOST': 'IPADDR1',
'PORT': '5432',
}
}
$ cat /etc/postgresql/14/main/pg_hba.conf
...
listen_addresses = 'localhost, 127.0.0.1, IPADDR1, IPADDR2, HOST1' # what IP address(es) to listen on;
...
Nothing changes - the site does not see information from the database and the error on the browser is the same. What other settings did I miss or what else can I do to make everything work correctly?