DEV Community

Cover image for Building Forum Service for Forum-Based Web using Redis (Part 3)
Bervianto Leo Pratama
Bervianto Leo Pratama

Posted on • Edited on

Building Forum Service for Forum-Based Web using Redis (Part 3)

Thread Service

I will fast forward for this service. Since the pattern will similar with previous service (User Service). You may check this changes:

Please, directly download/continue from this branch.

Notes:

  • I also change other services to add CORS, we need this since the Frontend and our microservices have a different domains.

Testing from Front End

We will need docker-compose.yml. We build the microservices into docker. This is my setup.

version: '3.9'
services:
  redis:
    image: redis/redis-stack:6.2.2-v4
    restart: always
    ports:
      - 6379:6379
      - 8001:8001
    volumes:
      - redis-data:/data
    networks:
      - backend
  mongodb:
    image: mongo:5
    restart: always
    networks:
      - backend
    ports:
      - 27017:27017
    volumes:
      - mongo-data:/data/db
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: secretpass
  mongo-express:
    image: mongo-express:latest
    restart: always
    networks:
      - backend
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: secretpass
      ME_CONFIG_MONGODB_URL: mongodb://root:secretpass@mongodb:27017/
  user-services:
    build: ./app/user-service
    networks:
      - backend
    ports:
      - 9000:80
    environment:
      ForumApiDatabase__ConnectionString: mongodb://root:secretpass@mongodb:27017
      RedisConnectionString: redis://redis:6379
      AuthServiceSettings__AuthServiceVerify: http://auth-services:5000/auth/verify
  auth-services:
    build: ./app/auth-service
    networks:
      - backend
    environment:
      NODE_ENV: production
      REDIS_CONNECTION_STRING: redis://redis:6379
      MONGO_CONNECTION_STRING: mongodb://root:secretpass@mongodb:27017
      PORT: 5000
    ports:
      - 9001:5000
  thread-services:
    build: ./app/thread-service
    networks:
      - backend
    environment:
      ForumApiDatabase__ConnectionString: mongodb://root:secretpass@mongodb:27017
      RedisConnectionString: redis://redis:6379
      AuthServiceSettings__AuthServiceVerify: http://auth-services:5000/auth/verify
    ports:
      - 9002:80


volumes:
  redis-data:
  mongo-data:

networks:
  backend:
    name: custom_backend
Enter fullscreen mode Exit fullscreen mode

You may run this command to build and turn on our services:

docker compose build # build our images (optional if you've built it)
docker compose up -d # turn on our services
Enter fullscreen mode Exit fullscreen mode

Front End

Initialize Project

npx create-react-app . --template typescript
Enter fullscreen mode Exit fullscreen mode

Populate Your Project

Since the step-by-step will be complex. You may try find out the changes using this PR (Pull Request).

Please, directly download from this branch.

Screenshot

  • Home Page

Home Page

  • Home Page (Not Login)

Not Login

  • Create Thread

Create Thread

  • Update Profile

Update Profile

This post is in collaboration with Redis.

References (Additional Resources)

There are many rooms of improvement. As example: Searching Thread using Redis, Searching Popular Thread using Redis (count by upvote and comments), etc.

Thank you

Thanks for reading. I will do some improvement to complete our projects. Here is the list:

  1. Comment Sections
  2. User Upvote
  3. Search Threads (using Redis)
  4. Popular Threads (using Redis)
  5. (Bonus) Deployment to AWS

So, please stay tune!

Thanks GIF

Top comments (0)