Last active
May 16, 2024 16:44
-
-
Save Apurer/1cd1fdf68869a0407e691ffb9705bd83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use an Ubuntu base image | |
FROM ubuntu:latest | |
# Install necessary dependencies | |
RUN apt-get update && apt-get install -y \ | |
nginx \ | |
curl \ | |
&& apt-get clean | |
# Install nvm (Node Version Manager) | |
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash | |
# Set environment variables for nvm | |
ENV NVM_DIR /root/.nvm | |
ENV NODE_VERSION 20 | |
# Install Node.js and npm using nvm, and install swagger-ui-dist globally | |
RUN bash -c ". $NVM_DIR/nvm.sh && \ | |
nvm install $NODE_VERSION && \ | |
nvm use $NODE_VERSION && \ | |
npm install -g swagger-ui-dist" | |
# Create a symbolic link for easier access to Swagger UI files | |
RUN ln -s /root/.nvm/versions/node/v$NODE_VERSION/lib/node_modules/swagger-ui-dist /usr/share/nginx/html/swagger-ui | |
# Copy Nginx configuration file | |
COPY nginx.conf /etc/nginx/sites-available/default | |
# Copy your custom Swagger file and custom index.html to the appropriate directory | |
COPY swagger.yaml /usr/share/nginx/html/swagger-ui/swagger.yaml | |
COPY index.html /usr/share/nginx/html/swagger-ui/index.html | |
# Ensure the permissions are correct | |
RUN chmod -R 755 /usr/share/nginx/html/swagger-ui | |
# Expose port 80 | |
EXPOSE 80 | |
# Start Nginx | |
CMD ["nginx", "-g", "daemon off;"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Swagger UI</title> | |
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" /> | |
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" /> | |
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" /> | |
<style> | |
html | |
{ | |
box-sizing: border-box; | |
overflow: -moz-scrollbars-vertical; | |
overflow-y: scroll; | |
} | |
*, | |
*:before, | |
*:after | |
{ | |
box-sizing: inherit; | |
} | |
body { | |
margin:0; | |
background: #fafafa; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="swagger-ui"></div> | |
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script> | |
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script> | |
<script> | |
window.onload = function() { | |
// Begin Swagger UI call region | |
const ui = SwaggerUIBundle({ | |
url: "./swagger.yaml", | |
dom_id: '#swagger-ui', | |
deepLinking: true, | |
presets: [ | |
SwaggerUIBundle.presets.apis, | |
SwaggerUIStandalonePreset | |
], | |
plugins: [ | |
SwaggerUIBundle.plugins.DownloadUrl | |
], | |
layout: "StandaloneLayout" | |
}) | |
// End Swagger UI call region | |
window.ui = ui | |
} | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name localhost; | |
location / { | |
root /usr/share/nginx/html/swagger-ui; | |
index index.html index.htm; | |
try_files $uri $uri/ /index.html; | |
} | |
location /swagger.yaml { | |
root /usr/share/nginx/html/swagger-ui; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment