diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..bb500c82 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM node:carbon + +ENV API_TITLE "ReDoc" +ENV API_URL "http://petstore.swagger.io/v2/swagger.json" +ENV PORT 8080 + +# install nginx +RUN apt-get update +RUN apt-get install nginx -y + +# generate bundle +WORKDIR /build +RUN npm install -g yarn --loglevel=warn +COPY . /build +RUN yarn install +RUN npm run bundle + +# copy files to the nginx folder +RUN cp bundles/* /usr/share/nginx/html +COPY index.tpl.html /usr/share/nginx/html/index.html +COPY nginx.conf /etc/nginx/ +COPY docker-run.sh /usr/share/nginx/ + +EXPOSE 8080 + +CMD ["sh", "/usr/share/nginx/docker-run.sh"] diff --git a/docker-run.sh b/docker-run.sh new file mode 100644 index 00000000..f1233133 --- /dev/null +++ b/docker-run.sh @@ -0,0 +1,17 @@ +#! /bin/sh + +set -e + +if [ -n "$API_TITLE" ]; then + sed -i "s|%API_TITLE%|$API_TITLE|g" /usr/share/nginx/html/index.html +fi + +if [ -n "$API_URL" ]; then + sed -i "s|%API_URL%|$API_URL|g" /usr/share/nginx/html/index.html +fi + +if [ -n "$PORT" ]; then + sed -i "s|8080|${PORT}|g" /etc/nginx/nginx.conf +fi + +exec nginx -g 'daemon off;' diff --git a/index.tpl.html b/index.tpl.html new file mode 100644 index 00000000..95fd40d7 --- /dev/null +++ b/index.tpl.html @@ -0,0 +1,25 @@ + + + + + + %API_TITLE% + + + + + + + + + + diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..94927db8 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,50 @@ +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; + index index.html index.htm; + + location / { + alias /usr/share/nginx/html/; + + 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'; + } + } + } +}