Giter Club home page Giter Club logo

Comments (6)

davidmorabito avatar davidmorabito commented on May 26, 2024 1

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.

kevinccbsg avatar kevinccbsg commented on May 26, 2024

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.

kdankert avatar kdankert commented on May 26, 2024

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.

kevinccbsg avatar kevinccbsg commented on May 26, 2024

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.

harshmandan avatar harshmandan commented on May 26, 2024

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.

harshmandan avatar harshmandan commented on May 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.