From 9afe6802db1191216b003d7f674644a2207ecaac Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Sat, 18 Mar 2017 13:58:30 -0700 Subject: [PATCH] added dockerfile instructions --- Dockerfile | 19 +++++++++++++++++++ README.md | 10 ++++++++++ nginx.conf | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..18c6d443 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM alpine:3.4 + +MAINTAINER fehguy + +RUN apk add --update nginx +RUN mkdir -p /run/nginx + +COPY nginx.conf /etc/nginx/ + +# copy swagger files to the `/js` folder +ADD ./dist/ /usr/share/nginx/html/js +ADD ./public/index.html /usr/share/nginx/html + +# change the folder structure +RUN sed -i 's/\.\.\/dist/js/g' /usr/share/nginx/html/index.html + +EXPOSE 8080 + +CMD exec nginx -g 'daemon off;' diff --git a/README.md b/README.md index ecac28c4..41fe6e28 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,16 @@ Swagger UI Version | Release Date | OpenAPI Spec compatibility | Notes | Status ### How to run +##### Easy start! Docker +You can pull a pre-built docker image of the swagger-ui directly from Dockerhub: + +``` +docker pull swaggerapi/swagger-ui +docker run -p 80:8080 swaggerapi/swagger-ui +``` + +Will start nginx with swagger-ui on port 80. + ##### Prerequisites - Node 6.x - NPM 3.x diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..dda3d6de --- /dev/null +++ b/nginx.conf @@ -0,0 +1,49 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + + sendfile on; + + keepalive_timeout 65; + + server { + listen 8080; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + # + # Custom headers and headers various browsers *should* be OK with but aren't + # + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + # + # Tell client that this pre-flight info is valid for 20 days + # + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + add_header 'Content-Length' 0; + return 204; + } + if ($request_method = 'POST') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + } + if ($request_method = 'GET') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; + } + } + } +}