Created
November 6, 2023 06:44
-
-
Save siteslave/7dcb68ecc464cd59fc78c293d98eb0e0 to your computer and use it in GitHub Desktop.
PostgreSQL + PostgREST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
postgrest: | |
image: postgrest/postgrest | |
environment: | |
PGRST_DB_URI: postgres://authenticator:passwrod@db:5432/app_db | |
PGRST_OPENAPI_SERVER_PROXY_URI: http://127.0.0.1:3000 | |
PGRST_JWT_SECRET: xxxxxxxxxx | |
PGRST_DB_MAX_ROWS: 500 | |
PGRST_DB_POOL: 50 | |
depends_on: | |
- db | |
db: | |
image: supabase/postgres | |
ports: | |
- "5444:5432" | |
environment: | |
POSTGRES_PASSWORD: xxxx | |
volumes: | |
- "./pgdata:/var/lib/postgresql/data" | |
nginx: | |
image: nginx:stable-alpine | |
ports: | |
- 8888:80 | |
volumes: | |
- ./nginx.conf:/etc/nginx/nginx.conf | |
restart: always |
Create JWT with role
in payload
{
"role": "userdb"
}
Use SDK
test.js
const postgrest = require('@supabase/postgrest-js')
const REST_URL = 'http://localhost:8888/api'
const accessToken = 'xxxxxxx'
const supabase = new postgrest.PostgrestClient(REST_URL, {
headers: {
'Authorization': 'Bearer ' + accessToken
}
})
async function main() {
const { data, error } = await supabase
.from('todos')
.select()
if (error) {
console.error(error)
}
console.log(data)
}
main();
Run:
node test.js
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
API Endpoint
http://localhost:8888/api