-
Notifications
You must be signed in to change notification settings - Fork 466
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
Serverless issue #199
Comments
@csakbalint I just ran into this the other day. The problem is that given a swagger path of if (event.path === '/swagger') {
event.path = '/swagger/';
} This cannot be done as a middleware as |
I have the similar problem. Swagger documentation doesn't work on AWS lambda using serverless framework. It works testing it locally ( What is very strange, that only one file .js and doesn't have 404. Others does. I have no idea why. Swagger API documentation: 404: 200: My part of configuration:
@jtmthf @csakbalint would you have any idea? |
Hi @plorencrstit , I am trying to use swagger with serverless and lambda functions. |
Hi @NastyZ98, Using TS and
in
|
@plorencrstit hi, thank you for your reply, I also added Here is my const binaryMimeTypes: string[] = [];
let cachedServer: Server;
process.on('unhandledRejection', reason => {
console.error(reason);
});
process.on('uncaughtException', reason => {
console.error(reason);
});
function setupSwagger(app: INestApplication) {
const options = new DocumentBuilder()
.setTitle('Tyffis API')
.setDescription('Tyffis REST API documentation')
.setVersion('1.0.0')
.addTag('tyffis')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);
}
async function bootstrapServer(): Promise<Server> {
if (!cachedServer) {
try {
const expressApp = express();
const adapter = new ExpressAdapter(expressApp);
const nestApp = await NestFactory.create(AppModule, adapter);
nestApp.use(eventContext());
await nestApp.init();
setupSwagger(nestApp);
cachedServer = createServer(expressApp, undefined, binaryMimeTypes);
} catch (error) {
return Promise.reject(error);
}
}
return Promise.resolve(cachedServer);
}
export const handler: Handler = async (event: any, context: Context) => {
if (event.path === '/api') {
event.path = '/api/';
}
event.path = event.path.includes('swagger-ui')
? `/api${event.path}`
: event.path;
cachedServer = await bootstrapServer();
return proxy(cachedServer, event, context, 'PROMISE').promise;
}; |
I had the same problem before with
I choose the configuration based on some Do you use |
Yes I use typeorm, your solution have fixed my problem concerning the entity :) ! But my swagger documentation still don't work.. Here is my functions:
index:
handler: src/lambda.handler
events:
- http:
cors: true
path: '/{proxy+}'
method: any Did I miss something in my |
Show the entire |
Here it is: service: tyffis-backend-test
provider:
name: aws
runtime: nodejs12.x
region: us-east-1
stage: dev
role: LambdaRole
memorySize: 512
vpc:
securityGroupIds:
- sg
subnetIds:
- ids
environment:
TYPEORM_HOST: ${self:custom.AURORA.HOST}
TYPEORM_PORT: ${self:custom.AURORA.PORT}
TYPEORM_USER: ${self:custom.USERNAME}
TYPEORM_PASSWORD: ${self:custom.PASSWORD}
TYPEORM_DB: ${self:custom.DB_NAME}
JWT_SECRET: secret
plugins:
- serverless-plugin-typescript
- serverless-plugin-optimize
- serverless-offline
package:
individually: true
custom:
DB_NAME: db_name
USERNAME: user
PASSWORD: pwd
AURORA:
HOST:
Fn::GetAtt: [AuroraRDSCluster, Endpoint.Address]
PORT:
Fn::GetAtt: [AuroraRDSCluster, Endpoint.Port]
optimize:
external: ['swagger-ui-dist']
resources:
Resources:
LambdaRole: ${file(./infra-serverless/LambdaRole.yml)}
AuroraRDSCluster: ${file(./infra-serverless/AuroraRDSCluster.yml)}
functions:
index:
handler: src/lambda.handler
events:
- http:
cors: true
path: '/{proxy+}'
method: any All my other routes work, I have authentication flow with jwt, I have no problem with them |
Try with:
|
It finally work !! 😄 await nestApp.init();
setupSwagger(nestApp); I copied https://gist.github.com/csakbalint/7fe406bd1b15124180a988c87d57cf9b from the original author to make my test but nestApp init has to be call before the setupSwagger function.. setupSwagger(nestApp);
await nestApp.init(); Thank you very much for your time @plorencrstit ! I Appreciate it! @csakbalint there is an error in your gist, look upper you switched your setupSwagger function with await nestApp.init(); one. |
@plorencrstit Thank you very much, you saved my day!! |
Hello guys! |
I'm submitting a...
Current behavior
Swagger endpoint is not found.
Expected behavior
Html response generated by swagger-ui.
Minimal reproduction of the problem with instructions
Here is an example I use in my project.
What is the motivation / use case for changing the behavior?
I'd like to generate swagger documents based on my modules and endpoints, but I cannot.
Environment
The text was updated successfully, but these errors were encountered: