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

/api-docs redirects to Swagger demo Pet Store when to portal is run in production environment #535

Closed
tschaffter opened this issue Sep 16, 2019 · 4 comments
Assignees
Labels
Bug Something isn't working Documentation
Milestone

Comments

@tschaffter
Copy link
Member

image

@tschaffter
Copy link
Member Author

Swagger is looking at the following files for the documentation:

    var swaggerJSDocOptions = {
        swaggerDefinition: swaggerDefinition,
        apis: [
            './**/api/**/index.js',
            './**/auth/**/*.js',
            './shared/interfaces/**/*.ts'
            // './**/swagger/**/*.ts'
        ]
    };

However these source files are not present in the production build. This is likely the issue, yet it is strange that Swagger decide by itself to show the Pet store demo if no documentation is passed instead of throwing an error.

A solution would compile the source files with the Swagger doc into a single file during npm run build, then make sure that Swagger looks for this output file in production mode. Moreover, we need to copy this file to the production docker image.

@tschaffter tschaffter added this to the Milestone 2 milestone Sep 18, 2019
tschaffter added a commit that referenced this issue Sep 24, 2019

Verified

This commit was signed with the committer’s verified signature.
shikanime Shikanime Deva
…ild. Currently using hardcoded path that works only on my computer (WIP) (#535)
@tschaffter tschaffter self-assigned this Oct 17, 2019
@tschaffter
Copy link
Member Author

tschaffter commented Oct 18, 2019

Notes

The idea is to keep the current setup in development environment. This way we benefit from the hot reloading of the dev server.

In production environment, I'll add a webpack task to compile swagger.json from the source files, then have the backend serve this file in production environment.

Part of this fix has already been implemented in #555, but as this PR is not going to be merged in Milestone 2, I'll extract part of it to fix this swagger issue right now.

@tschaffter
Copy link
Member Author

An issue was due to an update of swagger-ui-express. I implemented the solution describe here: scottie1984/swagger-ui-express#94

Thus I replaced:

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, swaggerOptions));

by

    const swaggerSetup = swaggerUi.setup(swaggerDocument, swaggerOptions);
    app.get('/api-docs/index.html', swaggerSetup);
    app.use('/api-docs', swaggerUi.serve);
    app.get('/api-docs', swaggerSetup);

Aside the source of the swagger definitions, I'm not sure why this issue hit only the production environment. Maybe the way the server and the client dev server serve routes.

@tschaffter
Copy link
Member Author

The fix is provided in the above PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Documentation
Projects
None yet
Development

No branches or pull requests

1 participant