Skip to content

Latest commit

 

History

History

server

SpaceOrbit-server

Running without Docker

Create .env file with the following content:

DATABASE_URL="file:./data/dev.db"

JWT_ACCESS_SECRET=SECRET123
JWT_REFRESH_SECRET=ANOTHER_SECRET123

npm install
npm run migrate
npm run dev

Server available at http://localhost:3010

Running in Docker

Dockerfile

Dockerfile -> Image

docker build --tag spaceorbit-server:1.0 .

Image -> Container

docker run -t -i -p 3010:3010 \
    --rm --name spaceorbit \
    --volume spaceorbitDB:/container/src/db/data \
    spaceorbit-server:1.0
  • -p forwards container's ports
  • -ti allows CTRL + C to stop container
  • --rm removes container after exit
  • --name becomes hostname for containers
  • --volume makes database data persistent by creating a named volume

Server available at http://localhost:3010

ER Diagram

Server API


Unfold to see the list of all API Routes of SpaceOrbit-server
POST /users/register

POST /users/login

POST /users/refreshToken

GET /users/me

POST /users/resetPassword

GET /users/resetPassword/:id

GET /users
POST /users

GET /users/:id
PATCH /users/:id
DELETE /users/:id

GET /endpoints

JWT

src/controllers/users/User.ts

src/services/auth/Auth.ts

src/utils/jwt.ts

Authentication

  • Refresh Token ― allows for acquirement of more Access Tokens
    • Valid for 8 hours
    • Requires check against db per use
    • Revocation is immediate
  • Access Token ― provides access to protected routes
    • Valid for 5 minutes
    • Does not require check against db per use
    • Revocation is not immediate: users could still use Access Token for up to 5 minutes even with revoked Refresh Token

Using access token on protected routes

Refreshing both tokens

Logout

Logout is achieved by clearing tokens from local/session storage on the client

Project structure

Repository design pattern