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

Migrate to 5.0.0-beta2 Swagger returns 404 #585

Closed
lo78cn opened this issue Apr 20, 2018 · 7 comments

Comments

@lo78cn
Copy link

commented Apr 20, 2018

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

npm start
no startup errors/issues, open swagger url in browser

{
"statusCode": 404,
"error": "Not Found",
"message": "Cannot GET /explorer/"
}

Expected behavior

Swagger web page

Minimal reproduction of the problem with instructions

I have followed the migration guide and replaced all decorators and attributes. I have updated the package.json file. Repo available as a download on request (private repo and I am not allowed to add more users). :-(

What is the motivation / use case for changing the behavior?

Environment


Nest version: 5.0.0-beta2

 
For Tooling issues:
- Node version: 8.9.1  
- Platform:  Mac

Others:
screen shot 2018-04-20 at 23 00 27


@kamilmysliwiec

This comment has been minimized.

Copy link
Member

commented Apr 21, 2018

Could you share your initialization file?

@lo78cn

This comment has been minimized.

Copy link
Author

commented Apr 21, 2018

Main.ts file:

import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { ApplicationModule } from './app.module';
import * as globals from './globals';
import { ValidationPipe } from './pipes/validation.pipe';

async function bootstrap() {
  const app = await NestFactory.create(ApplicationModule);
  app.enableCors();

  const options = new DocumentBuilder()
    .setTitle(globals.swaggerTitle)
    .setDescription(globals.swaggerDescription)
    .setVersion(globals.swaggerVersion)
    .setContactEmail(globals.swaggerContactEmail)
    .setBasePath(globals.swaggerBaseUrl)
    .addBearerAuth(globals.jwtHeaderName, globals.swaggerAuthLocation)
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup(globals.swaggerEndpoint, app, document);

  await app.listen(globals.port);
}
bootstrap();

Part of globals.ts file:

import * as path from 'path';
import * as dotenv from 'dotenv';

dotenv.config();

export const port = 3000;

// JSON Web Token (JWT)
export const jwtHeaderName: string = 'x-authorization';

// Swagger
export const swaggerEndpoint = '/explorer';
export const swaggerBaseUrl = '/';
export const swaggerAuthLocation = 'header';
export const swaggerContactEmail = 'support@test.eu';
export const swaggerVersion = '1.0.0';
export const swaggerTitle = 'title';
export const swaggerDescription = 'desc';
@kamilmysliwiec

This comment has been minimized.

Copy link
Member

commented Apr 21, 2018

Here is a swagger example https://github.com/nestjs/nest/tree/master/sample/11-swagger that looks almost the same as your code. I cannot reproduce your issue 🙁

@lo78cn

This comment has been minimized.

Copy link
Author

commented Apr 22, 2018

I have removed all my unnecessary code that results in a bare minimum 7kb zip file that reproduces the issue on my mac.

unzip
npm install
npm start
go to http://localhost:3000/explorer/
{
"statusCode": 404,
"error": "Not Found",
"message": "Cannot GET /explorer/"
}

swagger_minimum.zip

@lo78cn

This comment has been minimized.

Copy link
Author

commented Apr 22, 2018

Example shows the exact same issue on my mac in both Firefox and Chrome. https://github.com/nestjs/nest/tree/master/sample/11-swagger

download nest-master examples
extract zip
go to sample/11-swagger
    "@nestjs/common": "^5.0.0-beta.2",
    "@nestjs/core": "^5.0.0-beta.2",
    "@nestjs/microservices": "^5.0.0-beta.2",
    "@nestjs/swagger": "^1.1.2",
    "@nestjs/testing": "^5.0.0-beta.2",
    "@nestjs/websockets": "^5.0.0-beta.2",
npm install fastify-formbody --save
npm start
go to http://localhost:3001/api/
{
"statusCode": 404,
"error": "Not Found",
"message": "Cannot GET /api/"
}
@ruisaraiva19

This comment has been minimized.

Copy link

commented Apr 22, 2018

I have the same issue with version 5.0.0-beta.2 and it's now fixed with version 5.0.0-beta.3
@lo78cn try with nest version 5.0.0-beta.3

@kamilmysliwiec

This comment has been minimized.

Copy link
Member

commented Apr 22, 2018

@ruisaraiva19 @lo78cn this issue is fixed in v5.0.0-beta.3. Let me know if you face any issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.