0

I´m using the following setup to docker-compose my environment, and everything works fine as long I am using the ng client via localhost. From remote hosts where I am using the IP of the docker host, I am just able to use my nest api when the IP is also used inside the calls.

docker-compose.yaml:

services:
    evalapi:
        image: api
        ports:
            - '3000:3000'
        depends_on:
            - mongodb
        restart: unless-stopped
        networks:
            - docker

    evalweb:
        image: client
        ports:
            - "8090:8090"
        depends_on:
            - evalapi
        restart: unless-stopped
        networks:
            - docker

    mongodb:
        image: mongo:4.4.13
        container_name: "mongodb"
        hostname: "mongodb"
        ports:
            - 27017:27017
        environment:
            - MONGO_DATA_DIR=/data/db
            - MONGO_LOG_DIR=/dev/null
        volumes:
            - ./2log.io/mongo:/data/db
        command: mongod --logpath=/dev/null
        restart: unless-stopped
        networks:
            - docker

networks:
    docker:
        driver: bridge

example call from client to api:

export class LogService {

    constructor(private readonly http: HttpClient) { }

    getAllLogs(): Observable<LogDto[]> {
        return this.http.get<LogDto[]>(`http://192.168.0.36:3000/logs`, httpOptions);
    }

    getLogs(startdate: Date | undefined, enddate: Date | undefined, users: UserDto[]): Observable<LogDto[]> {
        return this.http.post<LogDto[]>(`http://192.168.0.36:3000/logs`, { startdate: startdate, enddate: enddate, users: users}, httpOptions);
    }
}

main.ts from nest api:

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.enableCors();
  await app.listen(3000, "192.168.0.36");
}
bootstrap();

How can I define my routes universally?

0

Browse other questions tagged or ask your own question.