Я хочу включить CORS для контейнера по умолчанию PHP Docker (https://hub.docker.com/_/php). Что такое конфигурация в docker -compose.yaml или docker -compose.yaml?
Это запрос от ReactJS с топором ios
class App extends React.Component {
... getUsers() {
axios.get(`http://127.0.0.1:8000/index.php/api`).then(res => {
this.setState({ users: res.data });
console.log(state.users);
// this.setState({ users });
});
}
ОШИБКА : Access to XMLHttpRequest at 'http://127.0.0.1:8000/index.php/api' from origin 'http://127.0.0.1:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
docker -compose.yaml
version: '3.3'
services:
web:
build:
context: ./php
dockerfile: Dockerfile
container_name: php74
depends_on:
- db
volumes:
- ./php:/var/www/html/
ports:
- 8000:80
db:
container_name: mysql8
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test_db
MYSQL_USER: devuser
MYSQL_PASSWORD: devpass
ports:
- 3306:3306
Dockerfile:
FROM php:7.4-apache
RUN apt-get update && apt-get upgrade -y
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
EXPOSE 80