Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

412
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda