Skip to content

Instantly share code, notes, and snippets.

@nfroidure
Last active February 8, 2022 14:23
Show Gist options
  • Save nfroidure/79f6f33b6907af59fb496365cd7a5054 to your computer and use it in GitHub Desktop.
Save nfroidure/79f6f33b6907af59fb496365cd7a5054 to your computer and use it in GitHub Desktop.
API docs with CORS

Usage

To use this with any API, just clone the Gist and run the following:

NGINX_API_URL=https://api.example.com API_PATH=/v0/openAPI docker-compose up

Finally browse to : http://docs.localhost:16640.

server {
listen ${NGINX_PORT} default_server;
server_name ${NGINX_HOST};
server_name_in_redirect off;
location / {
proxy_pass ${NGINX_API_URL};
proxy_hide_header Access-Control-Allow-Origin;
add_header 'Access-Control-Allow-Origin' 'http://docs.localhost:16640' always;
}
}
version: "3.5"
networks:
api_docs:
name: 'api_docs'
driver: bridge
# Avoid colliding with the AWS VPC subnet
ipam:
driver: default
config:
- subnet: 10.6.0.0/16
ip_range: 10.6.0.0/24
gateway: 10.6.0.1
aux_addresses:
swagger: 10.6.0.2
api: 10.6.0.3
services:
swagger:
image: swaggerapi/swagger-ui
networks:
- 'api_docs'
ports:
- "16640:8080"
environment:
- SWAGGER_JSON_URL=http://api.localhost:16641${API_PATH-/openapi.json}
api:
image: nginx
networks:
- 'api_docs'
volumes:
- ./default.conf.template:/etc/nginx/templates/default.conf.template
ports:
- "16641:80"
environment:
- NGINX_HOST=_
- NGINX_PORT=80
- NGINX_API_URL
@nfroidure
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment