Tuesday, 17 October 2023

Using Cors in Adonisjs 5

1: enable false => true

/*
|--------------------------------------------------------------------------
| Enabled
|--------------------------------------------------------------------------
|
| A boolean to enable or disable CORS integration from your AdonisJs
| application.
|
| Setting the value to `true` will enable the CORS for all HTTP request. However,
| you can define a function to enable/disable it on per request basis as well.
|
*/
enabled: true,

2. set origin value


// You can also use a function that return true or false.
// enabled: (request) => request.url().startsWith('/api')

/*
|--------------------------------------------------------------------------
| Origin
|--------------------------------------------------------------------------
|
| Set a list of origins to be allowed for `Access-Control-Allow-Origin`.
| The value can be one of the following:
|
| https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
| Boolean (true) - Allow current request origin.
| Boolean (false) - Disallow all.
| String - Comma separated list of allowed origins.
| Array - An array of allowed origins.
| String (*) - A wildcard (*) to allow all request origins.
| Function - Receives the current origin string and should return
| one of the above values.
|
*/
origin: ['http://localhost'],



Thank you


Sunday, 15 October 2023

Open port for PostgreSQL

=====================

- sudo nano /etc/postgresql/{version}/main/postgresql.conf

+ listen_addresses = '*'

// + port = 5433 (no needed)

- sudo nano /etc/postgresql/{version}/main/pg_hba.conf

+ host    all             all             [Your_IP_Can_Access]/32        md5 

- sudo service postgresql restart

- sudo ufw allow 5433/tcp
=====================
- access as root
$ sudo -u postgres psql
- show all dbs
$ \l

Connect to the PostgreSQL Database 
\c taximailinhdb;

Grant all privileges on the database:
GRANT ALL PRIVILEGES ON DATABASE hangchatgiagocdb TO hangchatgiagocuser;

Grant all privileges on all existing tables in the database: 
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO hangchatgiagocuser;

Grant all privileges on all sequences (if you are using sequences): 
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO hangchatgiagocuser;

Optionally, grant privileges on all future tables and sequences:
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON TABLES TO hangchatgiagocuser;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON SEQUENCES TO hangchatgiagocuser;

Step 3: Verify Permissions (Optional) 
\dp

Golang Advanced Interview Q&A