hola amigos, no me funciona swagger en aws sabian, alguien me ayuda

0

aca esta el codigo: const swaggerJSDoc = require('swagger-jsdoc'); const swaggerUi = require('swagger-ui-express');

const options = { definition: { openapi: '3.0.0', info: { title: 'Blog Appi', version: '1.0.0',

    }
},
apis: ['./routes/auth.routes.js', './models/user.model.js','./routes/post.routes.js','./models/post.model.js','./routes/comment.routes.js','./models/comment.model.js','./routes/user.routes.js','./models/user.model.js','./sockets/index.js']

};

const swaggerSpec = swaggerJSDoc(options)

const swaggerDocs=(app, port)=>{ app.use('/api/v1/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); app.get('/api/v1/docs.js', (req, res)=>{ res.setHeader('Content-type', 'application/json') res.send(swaggerSpec) }) console.log(Docs are avalible at http://localhost:${port}/api/v1/docs) }

module.exports=swaggerDocs;

1개 답변
0
수락된 답변

English:

Your code seems to be fine in general, but there are a couple of things I would like to point out.

  1. Make sure all your file paths are correct. The most common errors usually come from incorrect file paths in the Swagger options. Verify that all the paths in the apis option are correct.

  2. The last console.log is not formatted correctly. It needs to be inside the reverse quotes (` `) so you can use string interpolation with ${port}. Here is the fix:

console.log(`Docs are available at http://localhost:${port}/api/v1/docs`);

If you continue to experience problems, it would be helpful to have more information about the errors you are getting. Are you getting any particular error messages?

Spanish:

Tu código parece estar bien en general, pero hay un par de cosas que me gustaría resaltar.

  1. Asegúrate de que todas las rutas de tus archivos estén correctas. Los errores más comunes suelen provenir de rutas de archivos incorrectas en las opciones de Swagger. Verifica que todas las rutas en la opción apis sean correctas.

  2. El último console.log no está correctamente formateado. Necesita estar dentro de las comillas inversas (` `) para que puedas usar interpolación de cadenas con ${port}. Aquí está la corrección:

console.log(`Docs are available at http://localhost:${port}/api/v1/docs`);

Si continúas experimentando problemas, sería útil tener más información sobre los errores que estás obteniendo. ¿Recibes algún mensaje de error en particular?

profile picture
전문가
답변함 일 년 전
  • Hello Ivan, look, all the API endpoints are working, the only thing that is not working is Swagger. It tries to load the page but it appears blank. Everything works perfectly on my local machine or PC.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠