Swagger not working (cors) in demo deploy
Opened this issue · 4 comments
Hi,
The swagger container can not access the openapi.json-file due to cors
I'm using the standard docker-compose.yaml
and docker compose up
Error message from Swagger:
Errors
Hide
Fetch error
Failed to fetch http://localhost:8080/api/openapi.json
Fetch error
Possible cross-origin (CORS) issue? The URL origin (http://localhost:8080) does not match the page (http://localhost:8081). Check the server returns the correct 'Access-Control-Allow-*' headers.
Request with curl:
$ curl -v -s http://localhost:8080/api/openapi.json > /dev/null
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /api/openapi.json HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200
< Cache-Control: private
< Set-Cookie: JSESSIONID=715DCA7790998002996D7447CAE9F0BC; Path=/; Secure; HttpOnly; SameSite=Strict
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.google.com https://www.google-analytics.com https://www.gstatic.com; style-src 'self' 'unsafe-inline'; img-src 'self'; font-src 'self';
< X-XSS-Protection: 1; mode=block
< X-Permitted-Cross-Domain-Policies: none
< Feature-Policy: camera 'none'; fullscreen 'self'; geolocation *; microphone 'self'
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Referrer-Policy: no-referrer
< Permissions-Policy: geolocation=(self)
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Thu, 05 Sep 2024 13:04:25 GMT
<
{ [72894 bytes data]
* Connection #0 to host localhost left intact
docker-compose.yaml
---
services:
zoo:
image: docker.io/zookeeper:3.9.2-jre-17
restart: unless-stopped
environment:
- ZOO_4LW_COMMANDS_WHITELIST=mntr,conf,ruok
volumes:
- zookeeper_data:/data
- zookeeper_datalog:/datalog
solr:
image: docker.io/solr:9.5.0
restart: unless-stopped
ports:
- "8983:8983"
environment:
SOLR_HEAP: 2g
ZK_HOST: zoo:2181
command: -c
volumes:
- solr_data:/var/solr
clamd:
image: docker.io/clamav/clamav:1.2.2
restart: unless-stopped
volumes:
- clam_data:/var/lib/clamav
- roda_data:/roda/data/
siegfried:
image: ghcr.io/keeps/siegfried:v1.11.0
restart: unless-stopped
environment:
SIEGFRIED_HOST: 0.0.0.0
SIEGFRIED_PORT: 5138
volumes:
- siegfried_data:/root/siegfried/
- roda_data:/roda/data/
swagger:
image: docker.io/swaggerapi/swagger-ui:v5.13.0
restart: on-failure
ports:
- "8081:8080"
environment:
- URL=http://localhost:8080/api/openapi.json
- DOC_EXPANSION=none
- VALIDATOR_URL=none
roda:
image: ghcr.io/keeps/roda:latest
restart: unless-stopped
ports:
- "8080:8080"
depends_on:
- solr
- clamd
- siegfried
volumes:
- roda_data:/roda/data/
environment:
# Solr Cloud configuration
- RODA_CORE_SOLR_TYPE=CLOUD
- RODA_CORE_SOLR_CLOUD_URLS=zoo:2181
- SOLR_NUM_SHARDS=4
- SOLR_REPLICATION_FACTOR=1
# Base plugin services configuration
- SIEGFRIED_SERVER_URL=http://siegfried:5138
- CLAMD_TCPADDR=clamd
- CLAMD_TCPSOCKET=3310
volumes:
zookeeper_data:
zookeeper_datalog:
solr_data:
clam_data:
siegfried_data:
roda_data:
All containers seem to be working:
$ docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
slask-clamd-1 docker.io/clamav/clamav:1.2.2 "/init" clamd 27 hours ago Up 27 hours (healthy) 3310/tcp, 7357/tcp
slask-roda-1 ghcr.io/keeps/roda:latest "/docker-entrypoint.…" roda 27 hours ago Up 27 hours 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp
slask-siegfried-1 ghcr.io/keeps/siegfried:v1.11.0 "/bin/sh -c 'sf -ser…" siegfried 27 hours ago Up 27 hours 5138/tcp
slask-solr-1 docker.io/solr:9.5.0 "docker-entrypoint.s…" solr 27 hours ago Up 27 hours 0.0.0.0:8983->8983/tcp, :::8983->8983/tcp
slask-swagger-1 docker.io/swaggerapi/swagger-ui:v5.13.0 "/docker-entrypoint.…" swagger 27 hours ago Up 27 hours 80/tcp, 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp
slask-zoo-1 docker.io/zookeeper:3.9.2-jre-17 "/docker-entrypoint.…" zoo 27 hours ago Up 27 hours 2181/tcp, 2888/tcp, 3888/tcp, 8080/tcp
Best way would be to use a HTTP router like traefik or nginx to route all services through the same domain and port. Alternatively, you would need to add CORS header, for which an HTTP router would still be the best approach.
Best way would be to use a HTTP router like traefik or nginx to route all services through the same domain and port. Alternatively, you would need to add CORS header, for which an HTTP router would still be the best approach.
Yes, I know how to fix this on my own, but would it not be good idea if the Swagger container worked out-of-the-box?
Right now the instructions at https://github.com/keeps/roda/blob/master/deploys/standalone/README.md are not correct.
REST-API documentation will be at http://localhost:8081/ (same passwords as in RODA)
Changing title of issue to reflect that the request is actually to incorporate these changes in the demo/example deployment available on the github project.
I played around with this and it seems to work
---
services:
zoo:
image: docker.io/zookeeper:3.9.2-jre-17
restart: unless-stopped
environment:
- ZOO_4LW_COMMANDS_WHITELIST=mntr,conf,ruok
volumes:
- zookeeper_data:/data
- zookeeper_datalog:/datalog
solr:
image: docker.io/solr:9.5.0
restart: unless-stopped
ports:
- "8983:8983"
environment:
SOLR_HEAP: 2g
ZK_HOST: zoo:2181
command: -c
volumes:
- solr_data:/var/solr
clamd:
image: docker.io/clamav/clamav:1.2.2
restart: unless-stopped
volumes:
- clam_data:/var/lib/clamav
- roda_data:/roda/data/
siegfried:
image: ghcr.io/keeps/siegfried:v1.11.0
restart: unless-stopped
environment:
SIEGFRIED_HOST: 0.0.0.0
SIEGFRIED_PORT: 5138
volumes:
- siegfried_data:/root/siegfried/
- roda_data:/roda/data/
swagger:
image: docker.io/swaggerapi/swagger-ui:v5.13.0
restart: on-failure
ports:
- "8081:8080"
environment:
- URL=http://localhost:8082/api/openapi.json
- DOC_EXPANSION=none
- VALIDATOR_URL=none
roda:
image: ghcr.io/keeps/roda:latest
restart: unless-stopped
ports:
- "8080:8080"
depends_on:
- solr
- clamd
- siegfried
volumes:
- roda_data:/roda/data/
environment:
# Solr Cloud configuration
- RODA_CORE_SOLR_TYPE=CLOUD
- RODA_CORE_SOLR_CLOUD_URLS=zoo:2181
- SOLR_NUM_SHARDS=4
- SOLR_REPLICATION_FACTOR=1
# Base plugin services configuration
- SIEGFRIED_SERVER_URL=http://siegfried:5138
- CLAMD_TCPADDR=clamd
- CLAMD_TCPSOCKET=3310
nginx:
image: nginx:stable-alpine
ports:
- "8082:80"
configs:
- source: nginx.conf
target: /etc/nginx/nginx.conf
volumes:
zookeeper_data:
zookeeper_datalog:
solr_data:
clam_data:
siegfried_data:
roda_data:
configs:
nginx.conf:
content: |
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$$remote_addr - $$remote_user [$$time_local] "$$request" '
'$$status $$body_bytes_sent "$$http_referer" '
'"$$http_user_agent" "$$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
proxy_set_header Host $$host;
add_header Access-Control-Allow-Origin *;
proxy_set_header X-Real-IP $$remote_addr;
proxy_pass http://roda:8080;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}