Building Forum Service for Forum-Based Web using Redis (Part 3)
Tags: redis, beginners, webdev, tutorial
Published: 2022-07-17 00:05:12


## Thread Service

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

{% embed https://github.com/bervProject/forum-api-microservices/pull/8 %}

Please, directly download/continue from this [branch](https://github.com/bervProject/forum/tree/step-3).

**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.

```yaml
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
```

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
```


## Front End

### Initialize Project

```bash
npx create-react-app . --template typescript
```

### Populate Your Project

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

{% embed https://github.com/bervProject/forum/pull/1 %}

Please, directly download from this [branch](https://github.com/bervProject/forum/tree/initial).

## Screenshot

* Home Page

![Home Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztsqyzgt88rgpzzoh6n0.png)

* Home Page (Not Login)

![Not Login](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6npkjkgonkmfwe2tx3i.png)

* Create Thread

![Create Thread](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpnjcgvbj26d8hr3viyw.png)
 
* Update Profile

![Update Profile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3bx7wgfkwoq5me6yoh3h.png)

> This post is in collaboration with Redis.

## References (Additional Resources)

- [Try Redis Cloud for free](https://redis.com/try-free/?utm_campaign=write_for_redis)
- [Watch this video on the benefits of Redis Cloud over other Redis providers](https://www.youtube.com/watch?v=vyxdC1qK4NE)
    {% youtube vyxdC1qK4NE %}
- [Redis Developer Hub - tools, guides, and tutorials about Redis](https://developer.redis.com/?utm_campaign=write_for_redis)
- [RedisInsight Desktop GUI](https://redis.io/docs/stack/insight/?utm_campaign=write_for_redis)

> 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](https://media.giphy.com/media/xUySTJE4SmnSWHe4c8/giphy.gif)