swagger-ui-bundle.js:3 Uncaught SyntaxError: Unexpected token ‘<‘ (at swagger-ui-bundle.js:3:1)
swagger-ui-standalone-preset.js:3 Uncaught SyntaxError: Unexpected token ‘<‘ (at swagger-ui-standalone-preset.js:3:1)
swagger-ui-init.js:658 Uncaught ReferenceError: SwaggerUIBundle is not defined
at window.onload (swagger-ui-init.js:658:7)
For some reason at production I am getting this error when I hit the /api-docs route. I’ve looked through many other guys sharing their problem with customCssUrl and etc. but nothing worked for me.
If anyone has any clue why swagger does not work on production (vercel) please share what could be the problem here.
const express = require('express');
const app = express();
const routes = require('../routes.js');
const { connectDB } = require('../config/database-config.js');
const errorHandler = require('./middlewares/error-middleware.js');
const { readEnvironmentFile } = require('../config/envFile.js');
const getFixturesCronJob = require('./jobs/get_fixtures_cron_job.js');
const calculateSuccessRateCronJob = require('./jobs/calculate_success_rate_cron_job.js');
const { swaggerUi } = require('../config/swagger-config.js');
const path = require('path');
const YAML = require('yamljs');
const swaggerFilePath = path.resolve(__dirname, './swagger.yaml');
const swaggerDocument = YAML.load(swaggerFilePath);
readEnvironmentFile();
connectDB();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(routes);
app.use(errorHandler);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.listen(7600, () => {
console.log(`Server started on port ${7600}`);
getFixturesCronJob.start();
calculateSuccessRateCronJob.start();
});
module.exports = app;