Comments (6)
I know this was closed time ago, I'm leaving how I fixed it for posterity:
Simple nginx reverse proxy configuration:
upstream api-your-app-here {
# IP and port where your app is running
server 0.0.0.0:8080;
}
server {
listen 80;
location /your-custom-url/ {
proxy-pass http://api-your-app-here/;
}
}
Use a middleware in your node app:
const options = {
...
swaggerUIPath: '/docs'
...
}
const forwardedPrefixSwagger = function (req, res, next) {
req.originalUrl = (req.headers['x-forwarded-prefix'] || '') + req.url
next()
}
app.use('/docs', forwardedPrefixSwagger)
expressJSDocSwagger(app)(options)
Hope it helps
from express-jsdoc-swagger.
Hi @kdankert,
Are you sure that if you can pass options to swagger-ui-express
instance this will be solved? 🤔
If that is the only thing missing I think we could enable more options to send here.
from express-jsdoc-swagger.
I don't really know right now. I only use the endpoint for the json files, so I can't unfortunately help you there anymore.
from express-jsdoc-swagger.
I'm closing this due to inactivity. The only thing we could add to this issue is this example where you can extend SwaggerUI config.
from express-jsdoc-swagger.
I don't have any fancy redirects at nginx level, still can't access the swagger UI. It works fine on localhost:xxxx/swagger
but does not work on api.mydomain.com/swagger
Here's the log from NGINX:
1xx.xx.xxx.xx - - [28/May/2021:10:49:59 +0000] "GET /swagger/ HTTP/1.1" 200 1308 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:49:59 +0000] "GET /swagger/swagger-ui.css HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:49:59 +0000] "GET /swagger/swagger-ui-bundle.js HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:50:00 +0000] "GET /swagger/swagger-ui-standalone-preset.js HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:50:00 +0000] "GET /swagger/swagger-ui-init.js HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:50:00 +0000] "GET /swagger/swagger-ui-init.js HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:50:00 +0000] "GET /swagger/favicon-32x32.png HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:50:00 +0000] "GET /swagger/favicon-16x16.png HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:50:02 +0000] "GET /swagger/swagger-ui.css HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:51:34 +0000] "GET /swagger/ HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:51:34 +0000] "GET /swagger/swagger-ui.css HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:51:34 +0000] "GET /swagger/swagger-ui-bundle.js HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:51:34 +0000] "GET /swagger/swagger-ui-init.js HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:51:34 +0000] "GET /swagger/swagger-ui-standalone-preset.js HTTP/1.1" 404 197 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
1xx.xx.xxx.xx - - [28/May/2021:10:53:45 +0000] "GET /c/ HTTP/1.1" 200 35 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66"
Here's my NGINX config:
server {
root /etc/node/live/uploads;
index index.html index.htm index.nginx-debian.html;
server_name api.xxx.com;
location ~* \.(pdf|css|html|js)$ {
expires 2d;
}
location ~* \.(jpg|jpeg|gif|png)$ {
expires 365d;
}
location /uploads
{
alias /etc/node/live/uploads;
}
location / {
proxy_pass http://nodes;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/apis.xxx.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/apis.xxx.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
upstream nodes {
ip_hash;
server 127.0.0.1:3066;
}
server {
if ($host = api.xxx.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name api.xxx.com;
listen 80;
return 404; # managed by Certbot
}
from express-jsdoc-swagger.
Removing these lines from the nginx config made it work:
location ~* \.(pdf|css|html|js)$ {
expires 2d;
}
location ~* \.(jpg|jpeg|gif|png)$ {
expires 365d;
}
from express-jsdoc-swagger.
Related Issues (20)
- How to use with Express Router
- Syntax for specifying JSON object fields and nested objects in one place HOT 3
- Format is missing in response HOT 1
- Security template for Cookie
- Add support for `@augments`/`@extends` tag HOT 2
- Allow specifying global security schema for all routes HOT 3
- Add support for OAS 3 callback documentation
- [BUG] Unable to render this definition HOT 1
- Authorization Header [BUG] HOT 3
- Theme? HOT 1
- import file contained typedef is not recognized HOT 2
- [BUG] Unable to render this definition (production) HOT 1
- Adding Typescript Schema types into the comments HOT 3
- Adding REQUEST Header for Apis HOT 2
- express-jsdoc-swagger sometimes fails generating code HOT 2
- [BUG] Cannot generate example using media type = application/problem+json
- [BUG] enum does not support integer type
- elastic beanstalk fails swagger with timeout
- Upgrade `glob` dependency to >= v10
- Support @ start symbol in property definition
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-jsdoc-swagger.