Skip to content

AntColonyQuantitative/api-legacy-express

Repository files navigation

Tougu Server

Environment setup

  1. Install Node.js.
brew install node
  1. Install PostgreSQL and initial.
# Load package (this line is used according to your computer's situation)
brew tap homebrew/core

# Recommended installation method
brew install postgresql@15

# Check version
psql -V 或者 psql --version

# Add environment variables
echo 'export PATH="/usr/local/opt/postgresql@15/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

# Start PostgreSQL service
brew services start postgresql@15

# Create user and initialize password
createuser postgres -P

# Create Database
createdb toguDb -O postgres -E UTF8 -e

# Connection
psql -h 127.0.0.1 -p 5432 -U postgres -d postgres

OR if you want to use docker To run a PostgreSQL database locally:.

  1. Run yarn initialize the package required for the project.
npm install -g yarn
yarn install
  1. Create api/.env file.
echo "DATABASE_URL=postgresql://postgres:TOUGU_ADMIN@localhost:5432/toguDb" >> .env
echo "JWT_SECRET=hello_tougu" >> .env

# Migrate local database
cd prisma/touguDb
npx prisma generate
npx prisma migrate reset
  1. Start server.
yarn start

Now you can see it on: http://localhost:4000/graphql

Now we can operate on the webpage, use mutation to create your first user

Operation:

mutation CreateUser($input: CreateUserInput!) {
  createUser(input: $input) {
    token
  }
}

Variables:

{
  "input": {
    "email": "admin@tougu.com",
    "password":"tougu_admin",
    "displayName": "admin",
    "mobile": "0412 345 678",
    "realName": "tougu_master",
    "ref": "admin"
  }
}

Authenticate user and get your user token before running queries

Running the following query to get a token

query AuthenticUser($email: String!, $password: String!) {
  authenticUser(email: $email, password: $password) {
    token
  }
}
{
"email": "admin@tougu.com",
"password": "tougu_admin"
}

Running your queries and mutations with a token

Running an example query like:

query GetUsers {
  getUsers {
    id
    email
  }
}

And put your token in Headers as:

Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTY5NzMyMzgwOCwiZXhwIjoxNjk3MzY3MDA4fQ.Xo4xASTWtz_I3-jAv5l-DGk9LDCy6RxkwMCmKtCGEd4

To run a PostgreSQL database locally:

  1. Install docker locally: https://www.docker.com/get-started
  2. Pull the PostgreSQL Image:
docker pull postgres
  1. Run a PostgreSQL Container:
docker run --name togudb -e POSTGRES_PASSWORD=TOUGU_ADMIN -e POSTGRES_DB=toguDb -p 5432:5432 -d postgres
  1. Wait for the Container to Start and check the container's status:
docker ps
  1. Download a DBeaver: https://dbeaver.io/download/, connect your db using DBeaver by using the following config:
Host: localhost
Port: 5432
Database: toguDb
Username: postgres
Password: TOUGU_ADMIN
  1. (optional). Stop and remove the container: (you need to run step 3 again once you remove it):
docker stop togudb
docker rm togudb

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published