Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It changing protocol from http to https on VPS and show blank page, while URL is on http #1006

Closed
taipoxin opened this issue Oct 23, 2020 · 4 comments

Comments

@taipoxin
Copy link

taipoxin commented Oct 23, 2020

I'm submitting a...


[ ] Regression 
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Hello guys, I have an issue on my server (on localhost everything is good) with requests from swagger page to its resources, it call https:// when I am on http://server:5556/docs/ . I see only blank page, without any data.
In Chrome Dev Tools I see Console logs:

GET https://{server}:5556/docs/swagger-ui.css net::ERR_SSL_PROTOCOL_ERROR
GET  https://{server}:5556/docs/swagger-ui-bundle.js net::ERR_SSL_PROTOCOL_ERROR
....

Looks like it calls https instead of http, but SSL is not configured on my API, and I am not use NGINX or something.
Its very important that problem isnt on localhost, its on my VPS.
There is my configuration (also problems are exists without bearer or addServer):

const options = new DocumentBuilder()
    .setTitle('NestJS Realworld Example App')
    .setDescription('The Realworld API description')
    .setVersion('1.0')
    .setBasePath('api/icw')
    .addServer('http://localhost:5556')
    .addServer(`http://${server}:5556`)
    .addBearerAuth()
    .build()
  const document = SwaggerModule.createDocument(app, options)

What I should do to fix the swagger ui page on http protocol?
I tried to find answers on swagger.io and Nest docs, but I dont know what I need to fix.

Thank you very much

Here is my Chrome DevTools /docs request inspect, why it call to https resources? How to fix that?
Без названия

Expected behavior

Going on /docs page should give us scheme, and requests should go on http instead of https protocol.

Environment


Nest version: 7.4.4
"@nestjs/swagger": "^4.6.1",
"swagger-ui-express": "^4.1.4",

 
For Tooling issues:
- Node version: 12.16.1 (LTS)  
- Platform:  Linux (Docker - node:lts-alpine) 

@nartc
Copy link
Contributor

nartc commented Oct 23, 2020

@taipoxin I'm pretty sure this is an issue on swagger-ui-express side. There's one similar but it was closed by the issue opener (scottie1984/swagger-ui-express#212). Can you try opening an issue on swagger-ui-express?

@taipoxin
Copy link
Author

@nartc Thank you, I'll look on swagger-ui-express

@taipoxin
Copy link
Author

taipoxin commented Oct 23, 2020

I discovered everything and find the issue, i just needed to remove helmet express plugin:

// app.use(helmet())

Looks like it forces finding resources on https scheme, even if it not configured yet. Thanks @nartc , I think you can close issue.

@nartc nartc closed this as completed Oct 23, 2020
@meSmashsta
Copy link

Guys no need to remove helmet, just move the swagger above the helmet registration like so:

const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('../swagger.json');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

app.use(helmet());

@nestjs nestjs locked and limited conversation to collaborators Apr 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants