Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

410
Visualizações
aws cdk: serve swagger ui with api gateway

I want to use AWS ApiGateway to serve a swagger-ui of an API from a lambda function using express. For this I want to use the endpoint GET /docs. My Lambda function swaggerUiLambdaHandler looks like this:

import express from 'express';
import serverless from 'serverless-http';
import swaggerUI from 'swagger-ui-express';

const options = {
  swaggerOptions: {
    url: 'https://petstore.swagger.io/v2/swagger.json',
  },
};

const app = express();
app.use('/v1/docs', swaggerUI.serve, swaggerUI.setup(undefined, options));

module.exports.handler = serverless(app);

In the cdk stack of the api, I added the following 2 endpoints for serving the index.html and the .js/.css resources:

const docs = myApi.root.addResource('docs');
docs.addMethod('GET', new apigw.LambdaIntegration(swaggerUiLambdaHandler));
const docsProxy = docs.addResource('{proxy+}');
docsProxy.addMethod('GET', new apigw.LambdaIntegration(swaggerUiLambdaHandler));

However, calling the endpoint with the browser, all network requests succeed but I get a white canvas and the error

Uncaught SyntaxError: Unexpected token '<'

Do you have any idea? I think it might be related to the content-type returned by api gateway, but I would appreciate some help.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda