У меня есть веб-приложение, написанное на Angular 7 с прокси и .NET Core 2.2 как WebAPI. Моя проблема в том, что локально все работает, но я не могу сделать какой-либо запрос из WebAPI в контейнере Codker, потому что я получаю
craftsmen.client_1 | [HPM] Rewriting path from "/api//CraftOffer/GetManyWithFilters/0/5?category=0" to "/Public//CraftOffer/GetManyWithFilters/0/5?category=0"
craftsmen.client_1 | [HPM] GET /api//CraftOffer/GetManyWithFilters/0/5?category=0 ~> https://localhost:5000
craftsmen.client_1 | [HPM] Rewriting path from "/api/CraftOffer/GetCategories" to "/Public/CraftOffer/GetCategories"
craftsmen.client_1 | [HPM] GET /api/CraftOffer/GetCategories ~> https://localhost:5000
craftsmen.client_1 | [HPM] Error occurred while trying to proxy request /Public//CraftOffer/GetManyWithFilters/0/5?category=0 from localhost:4200 to https://localhost:5000 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
craftsmen.client_1 | [HPM] Error occurred while trying to proxy request /Public/CraftOffer/GetCategories from localhost:4200 to https://localhost:5000 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
Как иметь возможность делать запросы для WebAPI из клиента в контейнере Docker?
Я пробовал:- изменить, чтобы изменить цель внутри proxy.conf.json
на https://craftsmen.webapi:5000
- изменение ASPNETCORE_URLS
с http на https- изменить, чтобы изменить цель внутри proxy.conf.json
на https://127.0.0.1:5000
Текущий proxy.conf.json
{
"/api/*": {
"target": "https://localhost:5000",
"secure": false,
"logLevel": "debug",
"changeOrigin": true,
"pathRewrite": {"api" : "Public"}
}
}
Текущий файл Docker для приложения Angular
# source https://mherman.org/blog/dockerizing-an-angular-app/
# base image
FROM node:12.2.0
# install chrome for protractor tests
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install -yq google-chrome-stable
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install
RUN npm install -g @angular/cli@7.3.9
# add app
COPY . /app
# start app
CMD ng serve --host 0.0.0.0
docker-compose.yml
version: '3'
services:
craftsmen.webapi:
build:
context: .
dockerfile: BackEnd/src/Craftsmen.WebApi/Dockerfile
ports:
- "5000:5000"
volumes:
- webapi:/webapi
networks:
- craftsmenservices_network
craftsmen.client:
build:
context: ./FrontEnd
dockerfile: Dockerfile
volumes:
- 'FrontEnd:/app'
- '/app/node_modules'
ports:
- '4200:4200'
networks:
- craftsmenservices_network
depends_on:
- craftsmen.webapi
links:
- craftsmen.webapi
craftsmenservices_network:
driver: bridge
volumes:
webapi:
FrontEnd:
Текущий Dockerfile для WebApi
FROM microsoft/dotnet:2.2-runtime AS base
WORKDIR /app
ENV ASPNETCORE_URLS https://*:5000
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY BackEnd/src/Craftsmen.WebApi/Craftsmen.WebApi.csproj src/Craftsmen.WebApi/
COPY BackEnd/src/Craftsmen.Infrastructure/Craftsmen.Infrastructure.csproj src/Craftsmen.Infrastructure/
COPY BackEnd/src/Craftsmen.Core/Craftsmen.Core.csproj src/Craftsmen.Core/
COPY BackEnd/src/Craftsmen.Contract/Craftsmen.Contract.csproj src/Craftsmen.Contract/
COPY BackEnd/src/Craftsmen.Database/Craftsmen.Database.csproj src/Craftsmen.Database/
RUN dotnet restore src/Craftsmen.WebApi/Craftsmen.WebApi.csproj
COPY ./BackEnd .
WORKDIR /src/src/Craftsmen.WebApi
COPY BackEnd/src/Craftsmen.WebApi/entrypoint.sh .
RUN dotnet build Craftsmen.WebApi.csproj -c Release -o /app
RUN chmod +x ./entrypoint.sh
CMD /bin/bash ./entrypoint.sh
Iожидайте, что сможете отправлять успешные запросы от Angular Client к WebApi