I am working on two projects namely administrator and authentication.
The administrator project is hosted locally on port 3002 and the authentication project is hosted locally on port 3005.
I did set up of swagger on administrator using libraries swagger-ui-express
and yamljs
.
The code for setting up swagger in app.js
is as below -
const swaggerUi = require('swagger-ui-express');
const YAML = require('yamljs');
const swaggerDocument = YAML.load('./swagger.yml');
const swaggerOptions = {
explorer: true,
validatorUrl: null,
customCss: '.swagger-ui .topbar { display: none }',
// customCssUrl: '/custom.css'
// customJs: '/custom.js'
};
app.use(
'/api-docs',
function (req, res, next) {
swaggerDocument.host = req.get('host');
req.swaggerDoc = swaggerDocument;
next();
},
swaggerUi.serve,
swaggerUi.setup(null, swaggerOptions)
);
I am able to call the APIs of the Administrator project since the setup of the swagger is in the same project (same server and same port). I have selected the appropriate server(localhost) and port(3005) for the authentication project from the list of server dropdowns. However, when I am trying to call the APIs of the Authentication project from the authentication project, I am getting a CORS error.
I read the documentation swagger documentation for the CORS error. As per the documentation, I added the relevant CORS headers while calling an API and did CORS set up in the backend for the express server as well.
A relevant related question in Java.