/svelte-postgrest-tutorial-app

a tutorial app utilizing svelte-postgrest-template commented in the following slide https://bit.ly/3GZVYBj

Primary LanguageSvelteMIT LicenseMIT

what & why?

prequisites for dev env

  1. postgrest - install according to instructions.
    1. pgjwt - postgresql jwt extension for postgrest auth
  2. nvm - to easily swap node/npm versions. tested with node v13.11.0.

cloning

npx degit https://github.com/guyromm/svelte-postgrest-template svelte-postgrest-app

package.json dependencies

nvm use ; ./npm-init.sh

.env

use envs/local.tpl to create an envs/local .env shell file, and then expand/eval it using ./setenv.sh

   function freeport() {
	FROM=$1
	TO=$2
	HOWMANY=$3
	comm -23 \
	     <(seq "$FROM" "$TO" | sort) \
	     <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) \
	    | shuf | head -n "$HOWMANY"
   }
 export APPNAME=$(basename $(pwd))
 export DBNAME=$APPNAME
 export APPPORT=$(freeport 3000 4000 1)
 export POSTGRESTPORT=$[APPPORT+1]
 export SERVERPORT=$[APPPORT+2]
 export JWTSECRET=$(head /dev/urandom | tr -dc A-F0-9 | head -c 64 ; echo '')

 cp envs/local.tpl envs/local
 sed -i -E "s/APPPORTREPLACE/$APPPORT/g" envs/local
 sed -i -E "s/SERVERPORTREPLACE/$SERVERPORT/g" envs/local
 sed -i -E "s/POSTGRESTPORTREPLACE/$POSTGRESTPORT/g" envs/local
 sed -i -E "s/DBNAMEREPLACE/$DBNAME/g" envs/local
 sed -i -E "s/JWTSECRETREPLACE/$JWTSECRET/g" envs/local
 ./setenv.sh local

database initialization

source .env
echo 'DBNAME:'$DBNAME
./db_init.sh

launch

./tmux.sh