Backed server for Dashboard with GraphQL
language query and SQLite
database.
Development:
node v^14.15.4
Production:
node v^14.15.4
screen v^4.01.00
Development:
yarn v^1.22.10
typescript v^4.1.3
eslint v7^18.0
gulp v^2.3.0
nodemon v^2.0.7
prisma v^2.16.0
Production:
yarn v^1.22.10
typescript v^4.1.3
prisma v^2.16.0
git clone https://github.com/atherdon/dash-back
cd dash-back
yarn install
Rename .env.example to .env
and set up your environment variables:
# 1 For Linux Database url (need change ${absPathToPWD} to /abs/path/to/project)
# 2 For Windows (file:./database/sqlite/dash.db)
DATABASE_URL=file://${absPathToPWD}/database/sqlite/dash.db
# List of allowed origins, in NODE_ENV !== production that origin is '*' everytime
CORS_ORIGIN=localhost,second.origin
# JWT token secret key
TOKEN_KEY=QpLwz7AqqUg0GU6VHLO31aR8zqoeMiJiYXIiLCJpY
# Public server url for app host via docker
DOCKER_SERVER_URL=http://my.domain
Start watch ts changes:
yarn ts
Start server:
yarn dev
Database migrations: src/prisma/migrations
Database schema: src/prisma/schema.prisma
Create new migration. This command delete all data from database:
yarn migrate:dev
Only delete data from database without create migration:
yarn migrate:reset
Get status of migrations:
yarn migrate:status
GraphQL types |
---|
Types for GraphQL Schema created automatically with package @graphql-codegen . When changed src/graphql/Schema.ts. To create types into src/types/graphql/index.d.ts run yarn codegen or simple run gulp and generated file will be changed everytime when Schema.ts saved. |
Local settings for vscode
in .vscode/settings.json`
For highlight specified syntax need install vscode extensions:
dbaeumer.vscode-eslint
graphql.vscode-graphql
esbenp.prettier-vscode
prisma/prisma
To run server in debug console need set up file .vscode/launch.json
"runtimeExecutable": "~/.nvm/versions/node/v14.15.4/bin/node"
And run debug F5
Attention! |
---|
Only Linux based OS support |
Build typescript:
yarn build
Run server in screen
:
yarn prod
Or |
---|
Run build and prod commands: yarn deploy |
Create database schemas from exists migrations:
yarn migrate
File 'postman.json' in resources/postman
Start without screen
in development mode:
yarn start
Start with environment variable NODE_ENV=test (in this case in result of requests added variable 'stdErrMessage'):
yarn prod:test
Before this command do not forgot yarn build
Firewall settings:
Open port 80 (and 443 for ssl)
Skip SSL settings
If needed SSL certificate do change file dockerfiles/web/Dockerfile
:
## Set "nginx-ssl.conf" instead "nginx.conf" if needed SSL
ARG USED_NGINX_CONF=./resources/nginx.conf
## If needed SSL do uncoment next lines and set paths to private and public parts of certificate
# COPY .certs certs
# RUN chown nginx:nginx -R certs
Copy your SSL certificate parts in .certs
directory, and change owner if needed:
chown user:user -R .certs
Check resources/nginx*.conf
certificate part names:
# Set ssl paths
ssl_certificate /home/web/certs/nginx-selfsigned.crt; // Certs without "." is a path of ".certs" copy into container
ssl_certificate_key /home/web/certs/private/nginx-selfsigned.key;
Change protocol in .env:
# Public url for your server
DOCKER_SERVER_URL=http://my.domain ## https if used SSL
Then...
Build docker containers:
docker-compose build
Start containers for test:
docker-compose up
Start containers detach:
docker-compose up -d
Show logs:
docker logs
Connect to container:
docker exec -it name sh
Open database explorer
yarn studio
Show actual log (production):
yarn logs
Focus screen
(production):
yarn focus
Start fill
scripts
yarn script fill
Format Prisma scheme
yarn format
- auth0 as simple and lazy way to do a login
- quick and simple deploys from pull requests(aws?)
front located here: https://github.com/atherdon/dashb
examples with data(durty version): https://github.com/atherdon/dash-back/data
- stage 0: simple crud on graphql. we can use sqllite for speed
- stage 1: authentification: to be discussed - simple for 10 ppl or BRAC with 2-3 roles
- stage 2: csv/json import script
- stage 3: simple additional functionality: search/filtration/basic calculations